我的 WSL 的问题是以下我的 WSL 无法在本地主机下的任何地方发出 cURL 请求。在这个例子中,我创建了一个返回 hello world 的页面。我的 cURL 看起来像这样(请注意,即使使用 http://,响应也是一样的)
curl -vvv localhost:80/hello_world.html
响应如下
* 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 0
curl: (7) Failed to connect to localhost port 80: Connection refused
Run Code Online (Sandbox Code Playgroud)
现在,如果我在 Powershell 上运行以下 cURL
curl http://localhost:80/hello_world.html
我得到的回应是
StatusCode : 200
StatusDescription : OK
Content : <h1> Hello World </h1>
RawContent : HTTP/1.1 200 …Run Code Online (Sandbox Code Playgroud) windows localhost curl windows-10 windows-subsystem-for-linux