Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9082

Windows 10 WSL cURL can't access localhost with error (Failed to connect to localhost port 80: Connection refused)

$
0
0

The issue with my WSL is the following my WSL can't make a cURL request anywhere under localhost. For this example, I have created a page that returns hello world.

My cURL looks like this (note that the response is the same even with http://)

curl -vvv localhost:80/hello_world.html

and the response is the following

*   Trying 127.0.0.1...* TCP_NODELAY set* connect to 127.0.0.1 port 80 failed: Connection refused* Failed to connect to localhost port 80: Connection refused* Closing connection 0curl: (7) Failed to connect to localhost port 80: Connection refused

Now if I run the following cURL on Powershell:

curl  http://localhost:80/hello_world.html

The response I get is

StatusCode        : 200StatusDescription : OKContent           : <h1> Hello World </h1>RawContent        : HTTP/1.1 200 OK                    Keep-Alive: timeout=5, max=100                    Connection: Keep-Alive                    Accept-Ranges: bytes                    Content-Length: 22                    Content-Type: text/html                    Date: Mon, 24 Feb 2020 09:52:20 GMT                    ETag: "16-59f4f46118cab...Forms             : {}Headers           : {[Keep-Alive, timeout=5, max=100], [Connection, Keep-Alive], [Accept-Ranges, bytes], [Content-Length, 22]...}    Images            : {}InputFields       : {}Links             : {}ParsedHtml        : System.__ComObjectRawContentLength  : 22

which returns the actual hello world and not the error message i get on WSL

eg curl: (7) Failed to connect to localhost port 80: Connection refused


Edit: The server runs in windows 10 machine and the curl also in the same windows 10 machine. Also, the windows are on Insider version 19569.100

Update: I checked out this Microsoft article that @Anaksunaman shared in the comments and followed the step that says to cat /etc/resolv.conf then from there I got my IP and tried the curl with my IP from resolv.conf and it worked but still with localhost doesn't seem to work also in the article it says

Depending on which version of Windows you're using, you might need to retrieve the IP address of the virtual machine. If your build is 18945 or higher, you can use localhost just like normal.

My build is higher than 18945 as I'm a windows insider user. Is there any way that I can map my IP (EG 111.222.333.444) to localhost? so when I do a CURL to localhost the curl actually uses the IP 111.222.333.444?


Viewing all articles
Browse latest Browse all 9082

Trending Articles