下载url地址的图片

// string url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=cNaaMfvhpb1vmcVRXRAdIjRX3eUFsk1sRVrbOaPkR-8Gbli4xJE22sI9uLaf3q_aCIesyUtZ7KC4WvOKN9XquxWCHviW5yqMDJxojm-MMHE&media_id=wcrGxYBc_CotfNILfPtIPZNZS8N4GGhSpAP561qKY1s2AWYZXgPAD6dekWgCrHjK";

string url = "http://mmbiz.qpic.cn/mmbiz/PwIlO51l7wuFyoFwAXfqPNETWCibjNACIt6ydN7vw8LeIwT7IjyG3eeribmK4rhibecvNKiaT2qeJRIWXLuKYPiaqtQ/0";
string path = @"D:\5555555555555555555555555.jpg";
// string file = string.Empty;
string content = string.Empty;
string strpath = string.Empty;
string savepath = string.Empty;


HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);

req.Method = "GET";
using (WebResponse wr = req.GetResponse())
{
HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();
strpath = myResponse.ResponseUri.ToString();
WebClient mywebclient = new WebClient();
savepath = Server.MapPath("Images") + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + (new Random()).Next().ToString().Substring(0, 4) + ".jpg";
try
{
mywebclient.DownloadFile(strpath, savepath);
// file = savepath;
}
catch (Exception ex)
{
savepath = ex.ToString();
}

}
// return file;

// WebClient WebClient = new WebClient();

//myWebClient.DownloadFile(myStringWebResource,fileName);
// WebClient.DownloadFile(address, "D::\\deeeeeeeeeeeeedd.png");
// Fcity.Core.FileSources.ChangeImageSize("D:\\QQ截图20141205121451.png", "D:\\ddd.png", 1000, 1000, ImageFormat.Jpeg);

return;

你可能感兴趣的:(url)