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
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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With