简体   繁体   中英

`new HttpRequestMessage(…)` in docker application cannot access internet?

The following code (.Net core 2.1, created using visual studio) runs without error if not in docker.

var uri = new Uri("https://usbtrustgateway.usbank.com/portal/login.do");
using(var request = new HttpRequestMessage(RequestUri: uri, Method: httpMethod)) {

However, it got the following error when running in docker(Linux) or debugging running "docker-compose" using Visual Studio?

{System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.CurlException: Couldn't connect to server at System.Net.Http.CurlHandler.ThrowIfCURLEError(CURLcode error) at System.Net.Http.CurlHandler.MultiAgent.FinishRequest(StrongToWeakReference``1 easyWrapper, CURLcode messageResult) --- End of inner exception stack trace --- at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)}

Following the github issue below, it seems that you have an underlying request error from as far the the exception tells. Not much info, you've got to check it out from the request side.

https://github.com/dotnet/corefx/issues/24472

Also, from a personal point of view, docker usually has issues with connectivity on my side so try playing the turn it off and on game and see if it works, else you'll have to debug things on the curl side. Might be the same as the github issue as stated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM