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

huangxiangcai_old

Новичок
Регистрация
23.03.2013
Сообщения
25
Благодарностей
4
Баллы
3

Обращаем Ваше внимание на то, что данный пользователь заблокирован.
Не рекомендуем проводить с huangxiangcai_old какие-либо сделки.

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;
}
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 706
Баллы
113
You can use simple GET action. Why do you need code?
 

Radzhab

Client
Регистрация
23.05.2014
Сообщения
1 500
Благодарностей
1 263
Баллы
113
C#:
string strFile = @"c:\img.jpg";
WebClient wc = new WebClient();
wc.DownloadFile("https://www.mysite.come/image.jpeg", strFile);
 

huangxiangcai_old

Новичок
Регистрация
23.03.2013
Сообщения
25
Благодарностей
4
Баллы
3

Обращаем Ваше внимание на то, что данный пользователь заблокирован.
Не рекомендуем проводить с huangxiangcai_old какие-либо сделки.

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
 

huangxiangcai_old

Новичок
Регистрация
23.03.2013
Сообщения
25
Благодарностей
4
Баллы
3

Обращаем Ваше внимание на то, что данный пользователь заблокирован.
Не рекомендуем проводить с huangxiangcai_old какие-либо сделки.

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 180
Баллы
113

huangxiangcai_old

Новичок
Регистрация
23.03.2013
Сообщения
25
Благодарностей
4
Баллы
3

Обращаем Ваше внимание на то, что данный пользователь заблокирован.
Не рекомендуем проводить с huangxiangcai_old какие-либо сделки.

Регистрация
10.07.2017
Сообщения
29
Благодарностей
1
Баллы
3
Thank for this answer. I was looking after it. :-)
 

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