Xamarin Android Rest API到Passlot-nameResolutionFailure
我正在使用RESTAPI访问Passlot,试图生成通行证/优惠券。似乎当我运行程序时,我得到了一个错误:“error:namesolutionfailure” 我有:Xamarin Android Rest API到Passlot-nameResolutionFailure,android,json,rest,xamarin,httprequest,Android,Json,Rest,Xamarin,Httprequest,我正在使用RESTAPI访问Passlot,试图生成通行证/优惠券。似乎当我运行程序时,我得到了一个错误:“error:namesolutionfailure” 我有: public static async Task<string> SendAndReceiveJsonRequest() { string responseStr = null; string uri = "https://api.passslot.co
public static async Task<string> SendAndReceiveJsonRequest()
{
string responseStr = null;
string uri = "https://api.passslot.com/v1/templates/my-template-ID/pass";
// Create a json string with a single key/value pair.
var json = new JObject (new JProperty ("lastName", lastName),
new JProperty ("firstName", firstName),
new JProperty ("percentOff", percentOff),
new JProperty ("offerDescription", offerDescription),
new JProperty ("entityName", entityName),
new JProperty ("expiry", expiry));
//Console.WriteLine ("Jake's JSON " + json.ToString ());
using (var httpClient = new HttpClient ())
{
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("My-Key-Here-xxx-xxx-xxx");
//create the http request content
HttpContent content = new StringContent(json.ToString());
try
{
// Send the json to the server using POST
Task<HttpResponseMessage> getResponse = httpClient.PostAsync(uri, content);
// Wait for the response and read it to a string var
HttpResponseMessage response = await getResponse;
responseStr = await response.Content.ReadAsStringAsync();
}
catch (Exception e)
{
Console.WriteLine("Error communicating with the server: " + e.Message);
}
}
return responseStr;
}
公共静态异步任务SendAndReceiveJsonRequest()
{
字符串responsest=null;
字符串uri=”https://api.passslot.com/v1/templates/my-template-ID/pass";
//使用单个键/值对创建json字符串。
var json=new JObject(新的JProperty(“lastName”,lastName),
新JProperty(“firstName”,firstName),
新JProperty(“percentOff”,percentOff),
新的JProperty(“offerDescription”,offerDescription),
新的JProperty(“entityName”,entityName),
新产权(“到期日”);
//Console.WriteLine(“Jake的JSON”+JSON.ToString());
使用(var httpClient=newhttpclient())
{
httpClient.DefaultRequestHeaders.Authorization=新系统.Net.Http.Headers.AuthenticationHeaderValue(“我的密钥在此xxx xxx”);
//创建http请求内容
HttpContent=newStringContent(json.ToString());
尝试
{
//使用POST将json发送到服务器
Task getResponse=httpClient.PostAsync(uri,内容);
//等待响应并将其读入字符串变量
HttpResponseMessage response=等待getResponse;
responsest=wait response.Content.ReadAsStringAsync();
}
捕获(例外e)
{
Console.WriteLine(“与服务器通信时出错:+e.Message”);
}
}
返回响应;
}
我通过Nexus4在安卓4.4上运行这个。我使用的是3G(不是wifi)
任何关于此处可能发生的情况以及我出错原因的提示。如果url请求在本地网络中,请检查主机设备中是否设置了url ip(智能手机、平板电脑的主机设置,无论您使用什么进行测试) 警察局。 要在android中编辑主机设置设备,您可以使用此应用程序
问题似乎是在调试模式下运行时出现的。在发布模式下可以。也许可以尝试发布一些应用程序输出