Unable to read data from the transport connection: The connection was closed error in console application

前端 未结 3 756
后悔当初
后悔当初 2021-01-04 13:08

I have this code in console application and it runs in a loop

 try
 {
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search);
      request         


        
相关标签:
3条回答
  • 2021-01-04 13:21

    After adding

    request.KeepAlive = false;
    request.ProtocolVersion = HttpVersion.Version10; 
    

    it works fine..

    I found it form this blog post

    WebRequest and Unable to read data from the transport connection Error

    0 讨论(0)
  • 2021-01-04 13:45

    I just tried the code, looping 10 times to load google.com and it worked for me. Is there something special about search - perhaps try replacing it with another uri. I did not include findForMatch - I assume it is not doing anything that would cause the exception.

    0 讨论(0)
  • 2021-01-04 13:48

    Try disposing the reader in the finally block of your try catch

    0 讨论(0)
提交回复
热议问题