【发布时间】:2021-03-02 15:13:12
【问题描述】:
谁能告诉我如何解决这个问题?
这是我的主页cs文件: MainPage.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;
}
【问题讨论】:
-
它无法连接到服务器 - 这是一个网络问题。我建议从使用服务器的 IP 或 FQDN 开始,而不是 localhost
标签: c# xamarin.forms webapi xamarin.uwp