httpClient不提供响应

问题描述 投票:0回答:1

我正在尝试调用Zoom Api for Access令牌。当我尝试与邮递员邮寄时,它工作得很好。但是从代码中它没有响应

ZoomApiLink_StepNo2

以下是以下详细信息

 public static async Task<String> PostTogetToken<T>(string requestUrl, string client_Secretkey) {
            ZoomToken hello = new ZoomToken();

            var EncodedURl = ApiService.Base64Encode(client_Secretkey);
            using (var _httpClient = new HttpClient()) {

                if (!string.IsNullOrEmpty(requestUrl))
                    _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Basic " + EncodedURl);

                var httpContent = new StringContent("", System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");

                var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(requestUrl)) {
                    Version = HttpVersion.Version11,
                    Content = httpContent
                };

                using (var response = await _httpClient.SendAsync(httpRequestMessage)) {
                    if (response.IsSuccessStatusCode) {
                        response.EnsureSuccessStatusCode();
                        return await response.Content.ReadAsStringAsync();
                    } else {
                        return await response.Content.ReadAsStringAsync();
                    }
                }
            }
        }
c# asp.net asp.net-mvc asp.net-core core
1个回答
0
投票

您正在看到一个常见的死锁问题,因为代码更上层的堆栈正在使用Resultblocking on asynchronous code

要解决,将Result更改为await并使用async all the way

© www.soinside.com 2019 - 2024. All rights reserved.