HttpWebRequest通过代理如何下载没有后缀的图片 新开一个IE,复制图片地址是否能打开有的生成图片的页面,判断了来源或者COOKIE,没有的话,是打不开的,需要伪造 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 noyester 你说的cookies我有添加进去的,添加cookie代码Request.Headers["Cookie"]=imageCookie;这个imageCookie是我从第一次请求中取出来的!下载验证码图片的请求代码: Request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url); Request.Headers["Cookie"] = frmStatrWap.imageCookie; WebProxy loProxy = new WebProxy("10.0.0.172", 80); Request.UseDefaultCredentials = true; Request.Proxy = loProxy; Request.Method = "GET"; Request.Referer = frmStatrWap.url; 用Fiddle抓包后一个字节一个字节的对比,如果你的程序发的包和浏览器发的一样了,没理由打不开.另外,如果抓包的页面设计到二级域名,.NET自带的cookie会有各种奇怪的问题发生. 我没有给Request添加cookie,只是在Headers里面设置了cookieId;Request.Headers["Cookie"] = frmStatrWap.imageCookie; 如果单独用IE打开可以看到图片,那说明你的请求代码有问题,你要设置请求内容类型,即要设置 Content-Type,至于是什么值,你可以打开浏览器监控一下,看看请求图片时用的是什么Content-Type。 这是我获取QQ验证码的代码: private static string contentType = "application/x-www-form-urlencoded"; private static string accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*"; private static string userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Zune 4.7; BOIE9;ZHCN)"; public static string referer = "http://ui.ptlogin2.qq.com/cgi-bin/login?appid=1006102&s_url=http://id.qq.com/index.html"; public static Stream GetStream(string url, CookieContainer cookieContainer) { HttpWebRequest httpWebRequest = null; HttpWebResponse httpWebResponse = null; try { httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); httpWebRequest.CookieContainer = cookieContainer; httpWebRequest.ContentType = contentType; httpWebRequest.Referer = referer; httpWebRequest.Accept = accept; httpWebRequest.UserAgent = userAgent; httpWebRequest.Method = "GET"; httpWebRequest.ServicePoint.ConnectionLimit = int.MaxValue; httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); return responseStream; } catch (Exception) { return null; } }直接这样使用就OK:img = Image.FromStream(Stream );你参考参考 我这边下载的验证码是手机wap网端的验证码。楼上的方法是下载不下来的! Entity FarmeWork中删除对象必须要先查询一次么? 菜鸟求助:C#向oracle插入date类型数据问题 C# 加载word时,使word中的保存按钮不可用 c#窗体 保存按钮 代码怎么写 求助 在线等 如何在程序中获取 Access 表的排序依据 并更改!!!!!!!!!1 如何访问文件、文件夹的属性 浮点数怎么取小数点前两位? ★★★简单问题:怎么让窗体最小化到屏幕左上角?? C#是否比Delphi,PB开发ERP系统有优势吗? 求助_用VS2005编写函数读取Excel文档时的困惑。。。。 刚学c#,构造函数和属性问题,望高手解答,谢谢 WPF问题,谁能给个思路
Request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
Request.Headers["Cookie"] = frmStatrWap.imageCookie;
WebProxy loProxy = new WebProxy("10.0.0.172", 80);
Request.UseDefaultCredentials = true;
Request.Proxy = loProxy;
Request.Method = "GET";
Request.Referer = frmStatrWap.url;
你要设置请求内容类型,即要设置 Content-Type,至于是什么值,你可以打开浏览器监控一下,看看请求图片时用的是什么Content-Type。
private static string accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";
private static string userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Zune 4.7; BOIE9;ZHCN)";
public static string referer = "http://ui.ptlogin2.qq.com/cgi-bin/login?appid=1006102&s_url=http://id.qq.com/index.html";
public static Stream GetStream(string url, CookieContainer cookieContainer)
{
HttpWebRequest httpWebRequest = null;
HttpWebResponse httpWebResponse = null; try
{
httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.CookieContainer = cookieContainer;
httpWebRequest.ContentType = contentType;
httpWebRequest.Referer = referer;
httpWebRequest.Accept = accept;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.Method = "GET";
httpWebRequest.ServicePoint.ConnectionLimit = int.MaxValue; httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream(); return responseStream;
}
catch (Exception)
{
return null;
}
}直接这样使用就OK:img = Image.FromStream(Stream );你参考参考