HttpClient PostAsync 在 windows phone 的情况下不响应,但在 android 和 ios 中工作正常

HttpClient PostAsync does not respond in case of windows phone but works fine in android and ios

HttpResponseMessage myResponse = myClient.PostAsync(theUri, theContent).Result;

我正在 theUri 中传递 uri 并在 theContent

中传递 json 数据

这在 android 和 ios 中工作正常,但在 windows 中没有响应 phone 此语句有任何错误

如果你使用 Result 意味着你的方法会阻塞。但是不推荐,因为会造成死锁。使用 Result 属性 或 Wait().

时需要小心

当您使用异步方法时,我建议您声明异步方法并使用 await 调用该函数。

public async Task Method()
{
    HttpResponseMessage myResponse = await myClient.PostAsync(theUri, theContent);
}

如果您不能将方法声明为异步,而您需要使用异步方法。我建议您使用此 class 将异步方法转换为同步方法: How would I run an async Task<T> method synchronously?