码迷,mamicode.com
首页 > Web开发 > 详细

下载url地址的图片

时间:2015-03-17 11:54:32      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

// 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地址的图片

标签:

原文地址:http://www.cnblogs.com/lyl6796910/p/4343742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!