[英]Create a HttpClient in Xamarin Forms in iOS
I have an ASP.Net Core API that is running.我有一个正在运行的 ASP.Net Core API。
I have a Xamarin Forms solution and in the main project and I have this class:我有一个 Xamarin Forms 解决方案,在主项目中,我有这个类:
public class GetSettings
{
public static async Task<SettingResponse> GetSetting()
{
SettingResponse setting = new SettingResponse();
var url = new Uri(string.Format(GetUrl.GenerateURL("GetSetting"), string.Empty));
var client = new HttpClient();
var response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
setting = JsonConvert.DeserializeObject<SettingResponse>(result);
}
else
{
setting = null;
}
return setting;
}
}
In the Android and iOS project I have this two lines:在 Android 和 iOS 项目中,我有这两行:
SettingResponse setting = new SettingResponse();
setting = await GetSettings.GetSetting();
In the Android project there is no problem and it works fine, but in the iOS project when getting to new HttpClient();
在Android项目中没有问题并且工作正常,但在iOS项目中使用
new HttpClient();
nothing happens and app does nothing.什么都没有发生,应用程序什么也不做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.