"SocketException: Name or service not known" when URL loads fine in browser

I have the following code:

var url = ""; var httpClient = new HttpClient(); var httpResponse = await httpClient.GetAsync(url); var content = await httpResponse.Content.ReadAsStringAsync(); 

When I run this, I get the following exception thrown:

System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) 

With an inner exception of:

System.Net.Http.HttpRequestException: Name or service not known ---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) 

There is additional call stack, but I don't see it as useful...

The really odd thing is that if I take the URL () and put it in a browser, it runs the call on my service just fine and returns the expected output.

Why would I get a "Name or service not known" exception, but have the same URL work fine in the browser?

Additional Information: If I replace the url with "", then it works fine. Which makes me think it is my service. But the service loads fine from the browser.... I am very confused.

3

1 Answer

I forgot that, because I am using docker containers, I cannot have one container address another container using the hostname and port number.

When I replaced myComputer.myDomain.net:44344 with the hostname of the container found in my docker file it all started working.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like