我使用REST API访问PassSlot,试图生成通行证/优惠券。似乎当我运行程序时,我得到了一个错误:"Error: NameResolutionFailure“。
我有:
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;
}我是通过Nexus 4在Android 4.4上运行这个程序的,我用的是3G (不是wifi)。
任何关于这里可能发生的事情以及为什么我会收到错误的提示。
发布于 2015-01-15 00:32:44
如果url请求在本地网络中,请检查主机设备中是否设置了url ip (智能手机、平板电脑的 hosts 设置,无论您用来测试什么)
警局。要在安卓系统中编辑主机设置设备,您可以使用此应用程序https://play.google.com/store/apps/details?id=com.nilhcem.hostseditor
https://stackoverflow.com/questions/25384440
复制相似问题