Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would my C# app fail on this REST request but but works fine through a browser?

I have a C# app and I am accessing some data over REST so I pass in a URL to get a JSON payload back. I access a few different URLs programmatically and they all work fine using this code below except one call.

Here is my code:

 var url = "http://theRESTURL.com/rest/API/myRequest";
 var results = GetHTTPClient().GetStringAsync(url).Result;
 var restResponse = new RestSharp.RestResponse();
 restResponse.Content = results;
 var _deserializer = new JsonDeserializer();

where GetHTTPClient() is using this code below:

private HttpClient GetHTTPClient()
{
  var httpClient = new HttpClient(new HttpClientHandler()
  {
     Credentials = new System.Net.NetworkCredential("usr", "pwd"),
     UseDefaultCredentials = false,
     UseProxy = true,
     Proxy = new WebProxy(new Uri("http://myproxy.com:8080")),
     AllowAutoRedirect = false
  });
  httpClient.Timeout = new TimeSpan(0,0, 3500);
  return httpClient;
 }

so as i said, the above code works fine but a bunch of different request but for one particular request, I am getting an exception inside of the

 .GetStringAsync(url).Result

call with the error:

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

I get that error after waiting for about 10 minutes. What is interesting is that if I put that same URL that isn't working into Internet Explorer directly I do get the JSON payload back (after about 10 minutes as well). So i am confused at why

  • It would work fine directly from the browser but fail when using the code above.
  • It fails on this one request but other requests using the same code work fine programmatically.

Any suggestions for things to try or things I should ask the owner of the server to check out on their end to help diagnose what is going on?

like image 850
leora Avatar asked Dec 31 '15 04:12

leora


People also ask

What should I delete when C drive is full?

Press Windows key+R together, type %temp%, select all and delete them. Then go to C drive, right click->properties->general->disk cleanup->clean up system files->select temporary files and delete them. Lastly, open settings->system->storage->configure storage sense->clean now. That should do the trick.

Why my C drive is always full?

Mostly, useless large junk files, big files, huge installed programs, and temporary files are taking up the most space in your system C drive after using your PC for a long time. So the other effective method you can try is to free up hard disk space.

What happens if my C drive is full?

In case the C drive memory space is full, then you have to move the unused data to a different drive and uninstall the installed applications which are not used frequently. You can also perform Disk Cleanup to reduce the number of unnecessary files on the drives, which can help the computer run faster.


1 Answers

I think the timeout is not an issue here, as the error states that connection has been closed remotely and the set timeout is about 58 minutes, which is more than enough compared to your other figures.

Have you tried looking at the requests itself? Might want to edit your question with those results.

like image 177
rdoubleui Avatar answered Sep 28 '22 20:09

rdoubleui