How to use a C# code download the Images in the webpage?

huangxiangcai_old

Новичок
Регистрация
23.03.2013
Сообщения
25
Реакции
4
Баллы
3
We always to use the CapthchaSaver to save the images in the webpage.but there a problem:When the images size out of the range .it can be quit .
so i want to use the C#code to download via HTTP.

The code I got from somewhere can be some problems
Some one help me .Thanks
The C# Code
---------------------------------------------------------------------------
public Bitmap Get_img()
{
Bitmap img = null;
HttpWebRequest req;
HttpWebResponse res = null;
try
{
System.Uri httpUrl = new System.Uri("http://xxx.com/xxx.png ");
req = (HttpWebRequest)(WebRequest.Create(httpUrl));
req.Timeout = 180000;
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0";
req.Accept = "en-US,en;q=0.5";
req.Method = "GET";
res = (HttpWebResponse)(req.GetResponse());
img = new Bitmap(res.GetResponseStream());
img.Save(@"E:/" + DateTime.Now.ToFileTime().ToString() + ".png");
}

catch (Exception ex)
{
string aa= ex.Message;
}
finally
{
res.Close();
}
return img;
}
 
You can use simple GET action. Why do you need code?
 
C#:
Развернуть Свернуть Копировать
string strFile = @"c:\img.jpg";
WebClient wc = new WebClient();
wc.DownloadFile("https://www.mysite.come/image.jpeg", strFile);
 
You can use simple GET action. Why do you need code?

Ok,very appreciated with your fast reply. The Get Action can download the file very nice but the problem is: How to save the images to the right path or folder ? For eg. I want to save the "XXX.jpg" to "C:\mydoucument\myfolder\XXX.jpg" .The default save path in Zennoposter is:"C:\Program Files\ZennoLab\ZennoPoster Pro\Progs\Trash\XXX.jpg "
Is there any other setting in the GET action?
save the folder.png
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)