Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin RestSharp POST method throwing request timeout error and name resolution error

I am trying to post data from Xamarin android app to Netsuite RESTlet api. Below code is working fine from asp.net web form c# using rest sharp library and also work on Postman Desktop app. But when i try to post data xamarin android app it throw below errors.

  • Response Error: name resolution error

and sometime it throw following error

request time out

                    var client = new RestClient("testclient.com");
                    var request = new RestRequest(Method.POST);
                    request.AddHeader("postman-token", "123-456-789-123-3654");
                    request.AddHeader("cache-control", "no-cache");
                    request.AddHeader("content-type", "application/json");
                    request.AddHeader("authorization", "NLAuth nlauth_account= 
                    12345678, [email protected], 
                    nlauth_signature=test123, nlauth_role=correctrole");
                    request.AddParameter(
                    "application/json", 
                    "[{ \"id\": \"123\", \t\"myid\": \"111\", \t\"qty\": \"4\" } , { \"id\": \"123\", \t\"myid\": \"618\", \t\"qty\": \"6\" } \n, { \"id\": \"123\", \t\"1234\": \"2037\", \t\"qty\": \"3\" } , { \"id\": \"123\", \t\"1243\": \"126\", \t\"qty\": \"2\" }]",
                    ParameterType.RequestBody);
                    IRestResponse response = client.Execute(request);
like image 326
Salman Avatar asked Jan 02 '18 10:01

Salman


2 Answers

There are several things you can try:

  1. Ensure all packages are up-to-date
  2. Use Fiddler to view network traffic and check the request going out and the response you are receiving. A tutorial can be found here
  3. Check that your request URL is complete (including the trailing '/' character for example), sometimes forgetting this causes a redirect and HttpClient sometimes has issues with that
  4. Replace RestSharp client with basic System.Net.HttpClient. This solution gives you less high-level approach, but you can see if the problem persists
like image 115
Martin Zikmund Avatar answered Nov 11 '22 09:11

Martin Zikmund


I remember having to deal with this problem once and I think the solution is to use the IP address directly instead of the domain which leads to said IP address. Please give it a shot and let me know if it helps.

like image 34
Raimo Avatar answered Nov 11 '22 09:11

Raimo