asp.net 求根据图片链接地址自动下载图片

迷茫的凡人 2011-11-10 09:13:23
如:http://www.autoimg.cn/upload/spec/3278/t_3278542731823.jpg
有没有什么方法根据类似这样的图片链接地址程序自动下载这个图片??
...全文
258 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
迷茫的凡人 2011-11-11
  • 打赏
  • 举报
回复
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);
迷茫的凡人 2011-11-10
  • 打赏
  • 举报
回复
有没有人知道啊
迷茫的凡人 2011-11-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 chaichangaini 的回复:]

404错误就是找不到图片!!
[/Quote]
我知道找不到图片,它伪造Referer了,
我想问怎样得到真实的Referer或者什么改
1800包吃包住 2011-11-10
  • 打赏
  • 举报
回复
404错误就是找不到图片!!
迷茫的凡人 2011-11-10
  • 打赏
  • 举报
回复
它这是伪造Referer了吧?
有没方法获取真实的Referer?
什么写??
迷茫的凡人 2011-11-10
  • 打赏
  • 举报
回复

#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) 未找到。”
请问什么解决???

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧