如何在Windows Phone 8.1物理设备上调用REST服务

时间:2014-08-28 06:36:50

标签: c# rest windows-phone-8.1

我在Windows Phone 8.1中调用REST服务,它在Simulator中运行但未在Device上运行。我卡在这里,怎么处理? 请参阅下面的代码:

 System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();

 HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:32002/XXXXX.svc/live_login?uname=abc&pwd=123");

 HttpResponseMessage response = await client.SendAsync(request);
 string data = await response.Content.ReadAsStringAsync();
 var dialog = new MessageDialog(data);
 await dialog.ShowAsync();

1 个答案:

答案 0 :(得分:4)

Localhost与您的设备和PC不同。

在设备上运行时,您的代码正在尝试连接到手机上的休息服务,这显然无法正常工作。