❔ Local Environment throwing exception when calling HttpClient.GetStringAsync
I am running the below code via Visual Studio Code, and a "The requested address is not valid in its context. (www.mypublicwebsite.com:443)" exception is thrown, an inner SocketException with error code 10049 is thrown too but I cannot figure out why it is called, I believe my local is setup to allow the program to connect to public internet sites.
using (var httpClient = new HttpClient()) {
await httpClient.GetStringAsync("https://www.mypublicwebsite.com");
}
10 Replies
I'm guesing that's an example URL and the actual URL does load (in your browser for example)?
the error code indicates that it can't find the IP behind the domain.
If it's a fresh domain or recently changed IP records, it could be a dns propagation issue.
Yep it's an example URL, the actual URL does load. It's as if my local machine won't access / recognize external URLs
hmm but your browser does? does it work with google.com or something else public? does it work with any http server you have running in your lan?
It doesn't work with google.com, I tried it with google and a load of other valid well-known sites and I'm getting the same error.
but it works on your browser and its in the same machine? no docker or VM or anything funny like that/
Yep works on the browser and it's in the same machine. I'm not using docker or a VM just using the C# extension to compile C# in VS Code
this is a smelly bug 😠
can you try it with an IP addres like
https://1.1.1.1
dns vibecheck
are you sure that its not another part of your code triggering the error?
its either that or you have some weirdness in your network. or im completely lostThis message is what solved it! I had a problem with my network. I reset the router and I am now getting responses!
ayyy nice! thanks for letting me know, it was nibbling at my brain
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.