【发布时间】:2014-08-19 13:17:13
【问题描述】:
我正在使用 REST API 访问 PassSlot 以尝试生成通行证/优惠券。似乎当我运行程序时出现错误:“错误: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)。
关于这里可能发生的事情以及我为什么会收到错误的任何提示。
【问题讨论】:
-
问题似乎是在调试模式下运行时。在发布模式下很好。
-
也许尝试发布一些应用程序输出
标签: android json rest xamarin httprequest