CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 32
  1. #16
    Join Date
    Jun 2008
    Posts
    2,477

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    I don't even believe that you get that far as this line will throw an exception every time because the URI isn't valid.

    Code:
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("");
    You can't pass an empty string into WebRequest.Create(). How do you expect to make a request with an invalid URI? You set a proxy IP, but you never actually tell the request what it is looking for.

  2. #17
    Join Date
    Sep 2011
    Posts
    69

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    No. In my initial post I said I edited out the details of the request so on my side I can see the site Im connecting too. It was all to keep my code safe and away from leechers.

  3. #18
    Join Date
    Jun 2008
    Posts
    2,477

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    Oh yes, right... the leechers.

    Well, what is the exception that is thrown and what is the InnerException (assuming there is one)?

  4. #19
    Join Date
    Sep 2011
    Posts
    69

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    What do you mean by exception? If by exception you mean error then the error I got was:

    The underlying connection was closed: An unexpected error occurred on a receive.

  5. #20
    Join Date
    Jun 2008
    Posts
    2,477

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    An exception is what is thrown. That is the message from the exception. Per the documentation, and one of these exceptions may be thrown:

    ProtocolViolationException
    The Method property is GET or HEAD.
    -or-
    KeepAlive is true, AllowWriteStreamBuffering is false, ContentLength is -1, SendChunked is false, and Method is POST or PUT.
    InvalidOperationException
    The GetRequestStream method is called more than once.
    -or-
    TransferEncoding is set to a value and SendChunked is false.
    NotSupportedException
    The request cache validator indicated that the response for this request can be served from the cache; however, requests that write data must not use the cache. This exception can occur if you are using a custom cache validator that is incorrectly implemented.
    WebException
    Abort was previously called.
    -or-
    The time-out period for the request expired.
    -or-
    An error occurred while processing the request.
    ObjectDisposedException
    In a .NET Compact Framework application, a request stream with zero content length was not obtained and closed correctly. For more information about handling zero content length requests, see Network Programming in the .NET Compact Framework.
    I'm guessing it is a WebException, but I don't like guessing. Also, each exception has an InnerException property. Check that and, if it is not null, tell us what type of exception it is and what its message was.

  6. #21
    Join Date
    Sep 2011
    Posts
    69

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    Alright :/ I set up a try catch statement where the catch statement should output the exception in a message. It showed the same error message I said earlier.

    Maybe Im trying to get the exception wrong. This is what Im doing:

    Code:
    try {
    ///CODE HERE
    }
    catch (Exception ex)
    {
    MessageBox.Show (ex.Message);
    
    }

  7. #22
    Join Date
    Jun 2008
    Posts
    2,477

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    ...*sigh*, I'm not interested in the message, I am interested in the exception type. An exception is a type like any other type in your code. It has properties, use them. When the error message pops up click the button at the bottom which says "Exception details". Honestly I really hope you're not intending on selling any software for quite some time.

  8. #23
    Join Date
    Sep 2011
    Posts
    69

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    Exception details? The button popped up showing the error, I looked all over the bottom of the program and the Microsoft C# Visual Studio and did not find an exception details. Are you sure you dont have the professional version or maybe an option that I have turned off?

  9. #24
    Join Date
    Jun 2008
    Posts
    2,477

    Re: The underlying connection was closed: An unexpected error occurred on a receive.


  10. #25
    Join Date
    Sep 2011
    Posts
    69

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    Oh now I understand. I removed the try and catch statements and this is what it said. Sorry if Im annoying and slow:


    Status: System.Net.WebExceptionStatus.ReceiveFailure

    Inner Exception: {"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}

    Response: null

  11. #26
    Join Date
    Sep 2011
    Posts
    69

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    P.S: I repped you

  12. #27
    Join Date
    Jun 2008
    Posts
    2,477

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    It may be a timeout issue. Try setting the Timout property to a larger value or disabling it completely to see if the call ever returns:

    Code:
    request.Timeout = -1;  // never time out
    That said, the default is 100,000 (ms), 100 seconds, so unless the connection is reeeeaaallly slow, that is probably not it.

    Unfortunately that error can occur for MANY different reasons. See all the results for this search:

    http://www.google.com/search?sourcei...he+remote+host

    I wish I had more useful information. Does it work without the proxy? You'll need to start removing variables one by one until it works.

  13. #28
    Join Date
    Sep 2011
    Posts
    69

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    I tried the timeout code but it still came up with the error. Also, yes the httpwebrequest works without the proxy code.

  14. #29
    Join Date
    Jun 2008
    Posts
    2,477

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    Ok, so it's something to do with the proxy, at least that's progress. I'm not sure what else to say other than to start tweaking things on the proxy side.

  15. #30
    Join Date
    Sep 2011
    Posts
    69

    Re: The underlying connection was closed: An unexpected error occurred on a receive.

    Yeah :/, I looked on the results of the Google search and havent found much good info. Ive also tried several proxies and I put them through a proxy checker to make sure they're alive.

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured