苏飞大神,首先感谢你的回答。很荣幸。
在网页打开那个请求的网页的时候,用httpwatch看到的cookie,跟用您论坛里写的那个httphelper请求回来的returnCookie,是不一样的,是不是我请求的时候,方式不对呢?下面是请求的代码:
[C#] 纯文本查看 复制代码 shopItem.URL = url;
//客户端访问信息
shopItem.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0";
shopItem.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
//是否需要跳转页面,返回最终结果
shopItem.Allowautoredirect = true;
//最大连接数
shopItem.Connectionlimit = 10;
//请求返回类型
shopItem.ContentType = "text/html";
//返回数据的编码
//shopItem.Encoding = Encoding.Default;
shopItem.Encoding = callBackEncoding;
shopItem.Expect100Continue = true;
WebHeaderCollection headerCollection = new WebHeaderCollection();
shopItem.Header = headerCollection;
shopItem.KeepAlive = true;
//shopItem.Host = "s.taobao.com";
shopItem.Host = host;
//请求方式
shopItem.Method = "GET";
//请求超时时间(毫秒)
//shopItem.Timeout = 60000;
shopItem.Timeout = timeOut;
//请求到当前URL的来源地址
//shopItem.Referer = "";
shopItem.Referer = referer;
//是否为全文小写
shopItem.IsToLower = false;
//跟随重定向的最大数目
shopItem.MaximumAutomaticRedirections = 100;
//获取或者设置请求的HTTP请求的版本,默认为11
shopItem.ProtocolVersion = System.Net.HttpVersion.Version11;
//返回数据类型:string类型时,result的HTML才会有值
shopItem.ResultType = ResultType.String;
#region 证书相关
//证书路径
shopItem.CerPath = cerFilePatch;
//509证书集合
shopItem.ClentCertificates = null;
#endregion
#region 代理服务器相关
//设置代理对象
//shopItem.WebProxy
//代理服务器IP
shopItem.ProxyIp = "";
//代理服务器用户名
shopItem.ProxyUserName = "";
//代理服务器密码
shopItem.ProxyPwd = "";
#endregion
#region POST请求时相关
//发送的字符串
shopItem.Postdata = "";
//数据Byte类型封装
shopItem.PostdataByte = null;
//数据类型
shopItem.PostDataType = PostDataType.String;
//写入POST数据超时时间
shopItem.ReadWriteTimeout = 100;
//POST请求的编码
//shopItem.PostEncoding
#endregion
#region 未定义的参数
//获取或者设置请求身份验证
//shopItem.ICredentials
//设置modifiedSince时间,默认为当前时间
//shopItem.IfModifiedSince = DateTime.Now;
//本地出口的IP地址和端口
//shopItem.IPEndPoint
#endregion
#region cookies相关
shopItem.Cookie = sendCookie;
shopItem.CookieCollection = null;
//cookie返回类型
shopItem.ResultCookieType = ResultCookieType.String;
#endregion
msg.Code = 0;
HttpResult resultInfo = this.GetHtml(shopItem);
msg.Messages = resultInfo.Html;
returnCookie = resultInfo.Cookie; |