我刚接触到Windows Phone 8.1应用程序开发。我在使用httpclient获取请求时无法获取API的响应。可以告诉任何人在Windows Phone 8.1中提供从服务器执行get请求的最佳方式。提前谢谢
答案 0 :(得分:1)
希望以下帮助
try{
var client = new HttpClient();
var uri = new Uri("your URI");
//Call. Get response by Async
var Response = await client.GetAsync(uri);
//Result & Code
var statusCode = Response.StatusCode;
//If Response is not Http 200
//then EnsureSuccessStatusCode will throw an exception
Response.EnsureSuccessStatusCode();
//Read the content of the response.
//In here expected response is a string.
//Accroding to Response you can change the Reading method.
//like ReadAsStreamAsync etc..
var ResponseText = await Response.Content.ReadAsStringAsync();
}
catch(Exception ex)
{
//...
}