The POST method of the Xamarin RestSharp method that throws a request timeout error and a name resolution error

I am trying to send data from a Xamarin android application to the Netsuite RESTlet api. The code below works fine from the cp.net asp.net web form using the rest of the sharp library, and also works in the Postman Desktop application. But when I try to publish xamarin android application data, it throws below errors.

  • Answer Error: Name Resolution Error

and someday he gives the following error

request timeout

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, nlauth_email=test@test.com , 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); 
+5
source share
2 answers

There are a few things you can try:

  • Make sure all packages are updated.
  • Use Fiddler to view network traffic and verify the request and response you receive. The tutorial can be found here.
  • Check that your request url is completed (including, for example, the trailing "/" character), sometimes forgetting about it causes a redirect, and HttpClient sometimes has problems with this
  • Replace the RestSharp basic System.Net.HttpClient client. This solution gives you a lower level approach, but you can see if the problem persists.
+2
source

I remember that I had to solve this problem once, and I think that the solution is to use the IP address directly instead of the domain that leads to the specified IP address. Please give him a chance and let me know if that helps.

0
source

Source: https://habr.com/ru/post/1274438/


All Articles