簡體   English   中英

等待HttpClient.SendAsync沒有響應

[英]await HttpClient.SendAsync is not responsive

我有一個返回輸出的curl命令。 Access Denied對我來說很好,XML輸出目前讓我感興趣。

在此輸入圖像描述

curl -v  -E C:\SEB\certificate.pfx --cert-type p12 -X GET https://test.api.bgw.baltics.sebgroup.com/v1/accounts/EE101010220279354221/current-transactions -H OrgId:22223338

我編寫了一個代碼片段,它應該與curl命令提供相同的功能,但響應變量返回null(當代碼到達行時)

response = await httpClient.SendAsync(request); 

程序退出,不再執行其他代碼。

我究竟做錯了什么? 為什么我不能像curl命令那樣獲取響應的內容?

提前謝謝你的幫助

C#中使用的代碼片段如下:

    public async Task HttpRequestAppAsync()
    {

                var handler = new HttpClientHandler {ClientCertificateOptions = ClientCertificateOption.Manual};
                handler.ClientCertificates.Add(new X509Certificate2("C:\\SEB\\certificate.pfx"));

                using (var httpClient = new HttpClient(handler))
                {
                    using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://test.api.bgw.baltics.sebgroup.com/v1/accounts/EE101010220279354221/current-transactions"))
                    {
                        request.Headers.TryAddWithoutValidation("OrgId", "22223338");
                        response = await httpClient.SendAsync(request);
                    }
                }

    }

似乎已經弄清楚了。 已經存在死鎖我需要做的就是添加一個額外的方法ConfigureAwait並將其設置為false

response = await httpClient.SendAsync(request).ConfigureAwait(false);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM