none
Creating a completely fresh HttpWebRequest RRS feed

  • Question

  • I am sorry if my question itself is wrong. If so, please let me know, then I will withdraw my question.

    I create an HttpWebRequest like so:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);

    Even though I did not restore any information such as cookies from my previous request, I suspect it is somehow affected. I suspect the .NET BCL somehow reuses certain parts or does not clear some internal state variables.

    The reason is that after some successive request, the web site refuses to respond (I created a new request), and only restarting my application solves the problem. Timing is not the cause, because delaying the next request did not solve the problem, and immediate restart of the program solved the problem.

    Is my suspicion plausible? If so, how can I create a completely fresh HttpWebRequest?


    Sunday, February 8, 2015 12:44 AM

Answers

  • Cookies are stored and may need to be deleted.  Some servers will not allow more than one webrequest from a client.  Even though you didn't restore the cookies they are still known by the server.  The server keeps track of the client IP address and cookie.  When you reconnect with the server the server will check the IP address and verify if the cookie matches your previous cookie.  The cookie is also stored in the your temporary folder and webrequest will check the server IP address in your temporary files and reuse a cookie.

    Try deleting the cookies using your IE application before executing your VS application and see if that allows you to reconnect.


    jdweng

    Sunday, February 8, 2015 9:12 AM

All replies

  • Cookies are stored and may need to be deleted.  Some servers will not allow more than one webrequest from a client.  Even though you didn't restore the cookies they are still known by the server.  The server keeps track of the client IP address and cookie.  When you reconnect with the server the server will check the IP address and verify if the cookie matches your previous cookie.  The cookie is also stored in the your temporary folder and webrequest will check the server IP address in your temporary files and reuse a cookie.

    Try deleting the cookies using your IE application before executing your VS application and see if that allows you to reconnect.


    jdweng

    Sunday, February 8, 2015 9:12 AM
  • No, it was not the cookies. 

    I have found an answer at Stack Overflow. I followed the selected answer to close the underlying connection, and it solved my problem.

    Basically it is like this.

    request.ConnectionGroupName = "someuniquename";
    ....
    
    //Close the underlying connection for good.
    var x = ServicePointManager.FindServicePoint(new Uri(address));
    x.CloseConnectionGroup("someuniquename");
    

    Sunday, May 17, 2015 2:32 AM