Stesvis-5434 avatar image
0 Votes"
Stesvis-5434 asked WenyanZhang-MSFT commented

HttpClient vs RestSharp

Silly question, but i am wondering if switching from HttpClient to RestSharp to execute API calls in my xamarin forms app would/could be beneficial in terms of stability, reliability and or speed.

I am getting lots of httpclient/network related errors from my users and they all happen during a GET/POST/PUT call....


  • System.Net.Http.HttpRequestException or System.Net.WebException: Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." [my comment: the endpoint is live and working fine]

  • NativeMessageHandler.SendAsync or NSUrlSessionHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) / System.Threading.Tasks.TaskCanceledException: A task was canceled.

  • System.Net.Http.HttpRequestException or System.Net.WebException: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."

  • System.Net.WebException: Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."

  • System.ObjectDisposedException: Cannot access a closed Stream


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Each of the errors you got have a cause and should be analyzed first. Turning to RestSharp won't help as it does the same HTTP operations and can trigger the same kind of errors if your network settings are incorrect. For example, "A server with the specified hostname could not be found" is usually caused by DNS misconfiguration, and without fixing that RestSharp should give you a similar error.

0 Votes 0 ·

As lextm said, it is no matter about which libiary tool you choose, you could check the connection first.

0 Votes 0 ·

The interesting part is that i already do. If there is no connection i show a toast and don't execute the request.
I do this before every call..and still get many of these errors.

0 Votes 0 ·

Could you determine which http request returned the error message? I'm afraid this requires server-side help to fix this issue.

0 Votes 0 ·

0 Answers