iOS Httpclient 无法连接:{System.Threading.Tasks.TaskCanceledException}

iOS Httpclient cannot connect: {System.Threading.Tasks.TaskCanceledException}

我正在使用 Xamarin Forms 构建应用程序。我对 Android 没有任何问题,但是当我尝试模拟或部署 iOS 应用程序时,我的 HttpClient 似乎无法连接到服务器。超时到期后,我收到 TaskCanceledException。

HttpClient 实际上在一个单独的项目中使用,该项目被 iOS 应用程序引用,如果这很重要的话。这是我的用法:

string serviceUri = service + methodName;

            HttpRequestMessage request = new HttpRequestMessage(methodRequestType, serviceUri)
            {
                Content = new StringContent(content, Encoding.UTF8, "application/json")
            };

            HttpResponseMessage response = await _client.SendAsync(request).ConfigureAwait(false);
            string returnString = await response.Content.ReadAsStringAsync();
            return returnString;

我没有使用任何等待或访问 .Result,因为我看到很多人尝试不理解异步操作。

我看到较早的帖子(大约 2013 年)使用了错误的 HttpClient。这在当前版本中仍然是一个问题吗?我还尝试更改 iOS 项目设置中的 HttpClient 实现,但无济于事。

提前致谢!

问题是无效的部署目标 - 它被设置为“80”而不是“8.0

在某些情况下,构建服务器不会将此无效信息传回您的计算机 - 因此花了这么长时间才注意到它!