Capturing traffic by fiddler in .net 4.5

泄露秘密 提交于 2019-12-25 08:47:46

问题


I wrote simple application on VS2010 that send httpwebrequest and without any configurations fiddler is captures this request. But after, I installed VS2012 and run fiddler, and when i send request i have exception "Operation timed out" and request is no captured. When i close fiddler all requests are sends. I delete VS2012 and .net framework 4.5. After that request are sends and fiddler capturing them.
Why fiddler dont't capture traffic when .net4.5 installed?


回答1:


Did you by any chance try to set the Host property of the HttpWebRequest? This may be the cause of your problem.

I have also .NET 4.5 installed and experience the same situation. I get the same error when fiddler is running and is acting as a proxy. The error is:

System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()

Here is a trivial sample that reproduces the problem:

using System;
using System.IO;
using System.Net;

namespace WebRequestTest
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
            request.Host = "www.microsoft.com";//If I comment this line, capturing with fiddler works OK.
            request.Method = "GET";
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0";

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            using (Stream stream = response.GetResponseStream())
            using (StreamReader sr = new StreamReader(stream))
            {
                string content = sr.ReadToEnd();
                Console.WriteLine(content);
            }
        }
    }
}

In my case I just had to comment the request.Host="www.microsoft.com" line and everything worked OK.

I suspect same behavior will occur when using an HTTP proxy other than fiddler, but I have not tested it though.



来源:https://stackoverflow.com/questions/14170708/capturing-traffic-by-fiddler-in-net-4-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!