Ced*_*ore 7 c# api rest xamarin.forms
感谢您的关注。我正在尝试制作一个Xamarin.Forms与RESTAPI通信的应用程序。API 功能齐全,我已经用 Postman 和另一个 WPF 项目对其进行了测试。在尝试GET用 my调用一个简单的方法时HttpClient,我得到以下信息HttpResponseMessage
{
StatusCode: 400,
ReasonPhrase: 'Bad Request',
Version: 1.1,
Content: System.Net.Http.StreamContent,
Headers:
{
Server: Microsoft-HTTPAPI/2.0
Date: Sun, 17 May 2020 12:20:37 GMT
Connection: close
Content-Type: text/html; charset=us-ascii
Content-Length: 334
}
}
Run Code Online (Sandbox Code Playgroud)
{
StatusCode: 400,
ReasonPhrase: 'Bad Request',
Version: 1.1,
Content: System.Net.Http.StreamContent,
Headers:
{
Server: Microsoft-HTTPAPI/2.0
Date: Sun, 17 May 2020 12:20:37 GMT
Connection: close
Content-Type: text/html; charset=us-ascii
Content-Length: 334
}
}
Run Code Online (Sandbox Code Playgroud)
相同的代码由 WPF 程序运行并且可以完美运行。
我的手机和笔记本电脑都连接到同一个 Wi-Fi 网络。
44341通过防火墙,我什至尝试在关闭防火墙的情况下运行整个过程。我手机上的浏览器无法访问API。(错误的请求)https,http但遇到了trust anchor for certification path not found
我已将这些权限添加到android.manifest:CHANGE_NETWORK_STATE
CHANGE_WIFI_STATE
ACCESS_NETWORK_STATE
INTERNET
Run Code Online (Sandbox Code Playgroud)
API中的方法
[RoutePrefix("api/ChipCore")]
public class ValuesController : ApiController
{
[HttpGet]
[Route("TurnLEDOn")]
public bool TurnLEDOn()
{
return Switch.TurnLEDOn();
}
}
Run Code Online (Sandbox Code Playgroud)
更新
我已尝试通过将此行添加到绕过证书 MainActivity.cs
ServicePointManager.ServerCertificateValidationCallback += (o, cert, chain,
errors) => true;
我已经厌倦了在手机浏览器中输入 URL,我得到了 Error 400 - Bad Request
IIS Express 无法处理来自其他计算机的请求。
你可以:
安装我制作的名为 Conveyor 的免费扩展,它不会修改与您的项目或配置有关的任何内容https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti
或者,修改 IIS Express 中的配置如何在 IIS Express 中启用外部请求?
或者,将项目托管在 IIS 上
| 归档时间: |
|
| 查看次数: |
1433 次 |
| 最近记录: |