我正在尝试将数据从 Xamarin android 应用程序发布到 Netsuite RESTlet api。下面的代码使用 rest sharp 库从 asp.net web 表单 c# 运行良好,也适用于 Postman 桌面应用程序。但是当我尝试发布数据时,xamarin android 应用程序会抛出以下错误。
- Response Error: name resolution 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, 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);
最佳答案
有几件事你可以尝试:
- 确保所有包都是最新的
- 使用 Fiddler 查看网络流量并检查发出的请求和收到的响应。教程可以found here
- 检查您的请求 URL 是否完整(例如包括尾随的“/”字符),有时忘记这会导致重定向,而
HttpClient
有时会出现问题 - 将
RestSharp
客户端替换为 basicSystem.Net.HttpClient
.此解决方案为您提供了不太高级的方法,但您可以查看问题是否仍然存在
关于c# - Xamarin RestSharp POST 方法抛出请求超时错误和名称解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48059254/