有没有什么方法根据类似这样的图片链接地址程序自动下载这个图片??
6 个解决方案
#1
有没有人知道啊
#2
#region 根据图片链接地址下载图片
string fromURL = "http://www.autoimg.cn/upload/spec/3278/t_3278542731823.jpg";
string str1 = fromURL;
str1=str1.Replace("t_", "⊙");
string str = str1.Substring(str1.IndexOf("⊙")+1);
string fileName = str;
string savePath = Server.MapPath(fileName);
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(fromURL, savePath);
#endregion
WebResponse Resl = Http.GetResponse();
返回“远程服务器返回错误: (404) 未找到。”
请问什么解决???
#3
它这是伪造Referer了吧?
有没方法获取真实的Referer?
什么写??
有没方法获取真实的Referer?
什么写??
#4
404错误就是找不到图片!!
#5
我知道找不到图片,它伪造Referer了,
我想问怎样得到真实的Referer或者什么改
#6
string fpath = "~\\test\\"; \\要保存的图片本地文件夹路径
string fullPath = Path.GetFileName("t_3278542731823");\\要保存的图片自定义名称
string path = HttpContext.Current.Server.MapPath(fullPath);
if (!Directory.Exists(HttpContext.Current.Server.MapPath(fpath)))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(fpath));
}
returnPath = Path.Combine(fpath, fullPath);
HttpWebRequest wreq = (HttpWebRequest)HttpWebRequest.Create("http://www.autoimg.cn/upload/spec/3278/t_3278542731823.jpg");\\图片链接地址
wreq.Timeout = 10000;
wreq.Referer = "http://www.autohome.com.cn";\\出现链接地址访问 404 错误的解决代码
HttpWebResponse wresq = (HttpWebResponse)wreq.GetResponse();
Stream s = wresq.GetResponseStream();
System.Drawing.Image imgPic;
imgPic = System.Drawing.Image.FromStream(s);
returnPath = returnPath + ".jpg";
string pppp = HttpContext.Current.Server.MapPath(returnPath);
Bitmap bit = new Bitmap(imgPic);
bit.Save(pppp, System.Drawing.Imaging.ImageFormat.Jpeg);
string fullPath = Path.GetFileName("t_3278542731823");\\要保存的图片自定义名称
string path = HttpContext.Current.Server.MapPath(fullPath);
if (!Directory.Exists(HttpContext.Current.Server.MapPath(fpath)))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(fpath));
}
returnPath = Path.Combine(fpath, fullPath);
HttpWebRequest wreq = (HttpWebRequest)HttpWebRequest.Create("http://www.autoimg.cn/upload/spec/3278/t_3278542731823.jpg");\\图片链接地址
wreq.Timeout = 10000;
wreq.Referer = "http://www.autohome.com.cn";\\出现链接地址访问 404 错误的解决代码
HttpWebResponse wresq = (HttpWebResponse)wreq.GetResponse();
Stream s = wresq.GetResponseStream();
System.Drawing.Image imgPic;
imgPic = System.Drawing.Image.FromStream(s);
returnPath = returnPath + ".jpg";
string pppp = HttpContext.Current.Server.MapPath(returnPath);
Bitmap bit = new Bitmap(imgPic);
bit.Save(pppp, System.Drawing.Imaging.ImageFormat.Jpeg);
#1
有没有人知道啊
#2
#region 根据图片链接地址下载图片
string fromURL = "http://www.autoimg.cn/upload/spec/3278/t_3278542731823.jpg";
string str1 = fromURL;
str1=str1.Replace("t_", "⊙");
string str = str1.Substring(str1.IndexOf("⊙")+1);
string fileName = str;
string savePath = Server.MapPath(fileName);
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(fromURL, savePath);
#endregion
WebResponse Resl = Http.GetResponse();
返回“远程服务器返回错误: (404) 未找到。”
请问什么解决???
#3
它这是伪造Referer了吧?
有没方法获取真实的Referer?
什么写??
有没方法获取真实的Referer?
什么写??
#4
404错误就是找不到图片!!
#5
我知道找不到图片,它伪造Referer了,
我想问怎样得到真实的Referer或者什么改
#6
string fpath = "~\\test\\"; \\要保存的图片本地文件夹路径
string fullPath = Path.GetFileName("t_3278542731823");\\要保存的图片自定义名称
string path = HttpContext.Current.Server.MapPath(fullPath);
if (!Directory.Exists(HttpContext.Current.Server.MapPath(fpath)))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(fpath));
}
returnPath = Path.Combine(fpath, fullPath);
HttpWebRequest wreq = (HttpWebRequest)HttpWebRequest.Create("http://www.autoimg.cn/upload/spec/3278/t_3278542731823.jpg");\\图片链接地址
wreq.Timeout = 10000;
wreq.Referer = "http://www.autohome.com.cn";\\出现链接地址访问 404 错误的解决代码
HttpWebResponse wresq = (HttpWebResponse)wreq.GetResponse();
Stream s = wresq.GetResponseStream();
System.Drawing.Image imgPic;
imgPic = System.Drawing.Image.FromStream(s);
returnPath = returnPath + ".jpg";
string pppp = HttpContext.Current.Server.MapPath(returnPath);
Bitmap bit = new Bitmap(imgPic);
bit.Save(pppp, System.Drawing.Imaging.ImageFormat.Jpeg);
string fullPath = Path.GetFileName("t_3278542731823");\\要保存的图片自定义名称
string path = HttpContext.Current.Server.MapPath(fullPath);
if (!Directory.Exists(HttpContext.Current.Server.MapPath(fpath)))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(fpath));
}
returnPath = Path.Combine(fpath, fullPath);
HttpWebRequest wreq = (HttpWebRequest)HttpWebRequest.Create("http://www.autoimg.cn/upload/spec/3278/t_3278542731823.jpg");\\图片链接地址
wreq.Timeout = 10000;
wreq.Referer = "http://www.autohome.com.cn";\\出现链接地址访问 404 错误的解决代码
HttpWebResponse wresq = (HttpWebResponse)wreq.GetResponse();
Stream s = wresq.GetResponseStream();
System.Drawing.Image imgPic;
imgPic = System.Drawing.Image.FromStream(s);
returnPath = returnPath + ".jpg";
string pppp = HttpContext.Current.Server.MapPath(returnPath);
Bitmap bit = new Bitmap(imgPic);
bit.Save(pppp, System.Drawing.Imaging.ImageFormat.Jpeg);