android - 无法从 Android 调用 Web 服务,但它可以从 UWP 工作
问题描述
我必须在 Xamarin 项目中实现 Web 服务。所以我创建了一个简单的 Web 服务来做一些测试。有我以前的代码:
using (HttpClient client = new HttpClient()) {
client.BaseAddress = new Uri("http://localhost:62056/");
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("DataTransferTest.svc/HelloWorld").Result;
string json = response.Content.ReadAsStringAsync().Result;
}
我已经尝试改变http://localhost:62056/
tohttp:10.0.0.2:62056
但没有任何改变。
我已经像这样配置了我的 ISS Express:
<site name="LogiStock.WebServices2" id="4">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="D:\TeamExplorer\LogiStock-1.0.1\LogiStock.WebServices2" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:62056:localhost" />
<binding protocol="http" bindingInformation="*:62056:192.168.90.139" />
<binding protocol="http" bindingInformation="*:62056:127.0.0.1" />
</bindings>
</site>
当我尝试此代码时出现错误:
出现一个或多个错误。发送请求时出错_Error: ConnectFailure (Connection denied) _Connection denied
我真的希望有人能帮助我,我真的不知道出了什么问题..
解决方案
只是为了确保您的清单文件中有以下行?
<uses-permission android:name="android.permission.INTERNET" />
推荐阅读
- php - Ubuntu PHP 存储库会过期吗?
- c# - 将空白工作表添加到工作簿
- python-3.x - 在 Python 中使用 dblquad 积分函数的正弦
- pyspark - 有点复杂的 PySpark 选择和聚合查询
- ios - 有没有办法从 Realm Cloud 中的实例中获取用户?
- r - 在函数中正确使用 str_replace_all
- c# - 如何使用 blazor 创建 cookie 客户端
- c# - 使用 C# 从 s3 存储桶下载文件
- c# - 如何在其控制器中强制转换 XAML 项?[C#],[Xamarin.Forms]
- string - 自动将单个字符从某个位置移动到另一个位置