|
楼主 |
发表于 2015-4-13 08:46:08
|
显示全部楼层
我用的是Fiddler4,我发现如果我不用HttpHelper库,用原生的.net库,是没有问题的,Fiddler是完全可以抓包的,但用了HttpHelper的库,就不行了,代码如下:
====================.net的原生库==================================
string url = "http://news.baidu.com/";
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "GET";
webRequest.Timeout = 100000;
webRequest.AllowAutoRedirect = true;
var httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
string responseContent;
using (var httpStreamReader = new StreamReader(httpWebResponse.GetResponseStream(),
Encoding.GetEncoding("utf-8")))
{
responseContent = httpStreamReader.ReadToEnd();
}
httpWebResponse.Close();
webRequest.Abort();
====================HttpHelper的库=================================
HttpHelper httpHelper = new HttpHelper();
HttpItem httpItem = new HttpItem()
{
URL = "http://news.baidu.com/",
Method = "get",
Allowautoredirect = true
};
HttpResult httpResult = httpHelper.GetHtml(httpItem);
string responseCookie = httpResult.Cookie;
string responseHtml = httpResult.Html;
HttpStatusCode statusCode = httpResult.StatusCode;
string statusCodeDescription = httpResult.StatusDescription; |
|