Http请求异常-无法建立与服务器的连接-UWP Web API



有人能告诉我如何解决这个问题吗?

这是我的主页cs文件:主页.cs

public MainPage()
{
InitializeComponent();
GetAccount();
}
async void GetAccount()
{
HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
// Pass the handler to httpclient(from you are calling api)
HttpClient httpClient = new HttpClient(clientHandler);
httpClient.Timeout = TimeSpan.FromMinutes(30);
var api = "https://localhost:xxxxx/API/Accounts";//web api
var response = await httpClient.GetStringAsync(api);//The error showed this line got problem
var user = JsonConvert.DeserializeObject<List<Account>>(response);
US.ItemsSource = user;
}

UWP中有一个沙盒,它禁止连接到您自己的应用程序未打开的localhost端口,它被称为"Net Isolation";。您可以通过以下方式授予权限:

c:>checknetisolation loopbackexempt -a -n=<package family name>

和丢弃权限:

c:>checknetisolation loopbackexempt -d -n=<package family name>

更多详细信息请点击此处:https://learn.microsoft.com/en-us/previous-versions/windows/apps/dn640582(v=获胜。10(?重定向自=MSDN

相关内容

  • 没有找到相关文章

最新更新