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

leora

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?

rdoubleui

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Ionic app works fine on browser but does not open in my phone

From Dev

Request works fine in browser but 403 in python

From Dev

App Engine "InvalidURLError: Invalid request URL" though the URL works fine in the browser

From Dev

DocuSignAPI REST - Why won't my OAuth request go through?

From Dev

Why does my multi part post request fail when sending from Marklogic instead of a browser form?

From Dev

Why would my REST service .NET clients send every request without authentication headers and then retry it with authentication header?

From Dev

Why does my redirected CORS request fail?

From Dev

Why would scenebuilder 2.0 fail to open my fxml file?

From Dev

ffmpeg won't build in my project, works fine in example app

From Dev

My Angular JS app works in desktop browser, but not in a mobile browser

From Dev

Why does my CSS not work as expected in Safari but it works fine on Chrome

From Dev

My localhost website using(angularjs bower components) works fine only on a particular browser and not on other computers and browser

From Dev

Why would UndoManager.canRedo() return false even though redo() works fine?

From Dev

Why does twilios call forwarding not work when I am calling through browser, but work fine when calling a twilio number with exact same request url

From Dev

Why does running Spark job fail to find classes inside uberjar on EMR while it works locally fine?

From Dev

Why does "sbt run" fail with OutOfMemoryError while "activator run" works fine?

From Dev

Why does "sbt run" fail with OutOfMemoryError while "activator run" works fine?

From Dev

Why does running Spark job fail to find classes inside uberjar on EMR while it works locally fine?

From Dev

Why does reading CSV file fail in cluster mode (while works fine in local)?

From Dev

HTTP_Request call works in browser, timeout in web app

From Dev

HTTP_Request call works in browser, timeout in web app

From Dev

BuddyBuild tests fail, but on local works fine

From Dev

Why does (python) gspread work fine from my Mac but fail silently from my CentOS host

From Dev

Why does (python) gspread work fine from my Mac but fail silently from my CentOS host

From Dev

Why the same POST request works in POSTMAN but not in browser AJAX (404 Not Found)?

From Dev

Why with base index 1 C program works fine?

From Dev

Symfony2 app.php receiving POST request as GET app_dev.php works fine

From Dev

Forcing an HTTP request to fail in browser

From Dev

Why is a request through JavaScript from a browser to localhost not blocked?

Related Related

  1. 1

    Ionic app works fine on browser but does not open in my phone

  2. 2

    Request works fine in browser but 403 in python

  3. 3

    App Engine "InvalidURLError: Invalid request URL" though the URL works fine in the browser

  4. 4

    DocuSignAPI REST - Why won't my OAuth request go through?

  5. 5

    Why does my multi part post request fail when sending from Marklogic instead of a browser form?

  6. 6

    Why would my REST service .NET clients send every request without authentication headers and then retry it with authentication header?

  7. 7

    Why does my redirected CORS request fail?

  8. 8

    Why would scenebuilder 2.0 fail to open my fxml file?

  9. 9

    ffmpeg won't build in my project, works fine in example app

  10. 10

    My Angular JS app works in desktop browser, but not in a mobile browser

  11. 11

    Why does my CSS not work as expected in Safari but it works fine on Chrome

  12. 12

    My localhost website using(angularjs bower components) works fine only on a particular browser and not on other computers and browser

  13. 13

    Why would UndoManager.canRedo() return false even though redo() works fine?

  14. 14

    Why does twilios call forwarding not work when I am calling through browser, but work fine when calling a twilio number with exact same request url

  15. 15

    Why does running Spark job fail to find classes inside uberjar on EMR while it works locally fine?

  16. 16

    Why does "sbt run" fail with OutOfMemoryError while "activator run" works fine?

  17. 17

    Why does "sbt run" fail with OutOfMemoryError while "activator run" works fine?

  18. 18

    Why does running Spark job fail to find classes inside uberjar on EMR while it works locally fine?

  19. 19

    Why does reading CSV file fail in cluster mode (while works fine in local)?

  20. 20

    HTTP_Request call works in browser, timeout in web app

  21. 21

    HTTP_Request call works in browser, timeout in web app

  22. 22

    BuddyBuild tests fail, but on local works fine

  23. 23

    Why does (python) gspread work fine from my Mac but fail silently from my CentOS host

  24. 24

    Why does (python) gspread work fine from my Mac but fail silently from my CentOS host

  25. 25

    Why the same POST request works in POSTMAN but not in browser AJAX (404 Not Found)?

  26. 26

    Why with base index 1 C program works fine?

  27. 27

    Symfony2 app.php receiving POST request as GET app_dev.php works fine

  28. 28

    Forcing an HTTP request to fail in browser

  29. 29

    Why is a request through JavaScript from a browser to localhost not blocked?

HotTag

Archive