HttpWebRequest times out on second call

后端 未结 8 560
猫巷女王i
猫巷女王i 2020-11-29 03:45

Why does the following code Timeout the second (and subsequent) time it is run?

The code hangs at:

using (Stream objStream = request.GetResponse().Ge         


        
8条回答
  •  猫巷女王i
    2020-11-29 04:40

    As you have stated, running fiddler in the background would mitigate the issue. This is because fiddler force closes any responses. Extending on the above post from Sam B I would ensure that the response is closed like so:

    using (var wresponse = request.GetResponse())
    {
       using (Stream objStream = wresponse.GetResponseStream())
       {
            // ...
       } 
       wresponse.close();
    }
    

    Also it may be worth setting the proxy to null like so:

     request.Proxy = Null;
    

    As the .NET framework will go out searching for a proxy unless you explicitly do this. When fiddler is running this effect would be mitigated as fiddlers proxy would be found directly.

提交回复
热议问题