#region C#抓取网络图片保存到本地
public static Bitmap GetRequestImg()
{
Bitmap img = null;
HttpWebRequest req;
HttpWebResponse res = null;
try
{
System.Uri httpUrl = new System.Uri("https://s3-us-west-1.amazonaws.com//web.noblehouse/53587.00/53587.00_1_th.jpg");
req = (HttpWebRequest)(WebRequest.Create(httpUrl));
req.Timeout = 180000; //设置超时值10秒
req.UserAgent = "XXXXX";
req.Accept = "XXXXXX";
req.Method = "GET";
res = (HttpWebResponse)(req.GetResponse());
img = new Bitmap(res.GetResponseStream());//获取图片流
string filePath = @"E:\ad";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
//img.Save(@"E:/" + DateTime.Now.ToFileTime().ToString() + ".jpg");//随机名
img.Save(filePath + @"\"+ DateTime.Now.ToFileTime().ToString() + ".jpg");//随机名
}
catch (Exception ex)
{
string aa = ex.Message;
}
finally
{
res.Close();
}
return img;
}
#endregion