小编The*_*is 的帖子

Windows 10 WSL cURL 无法访问本地主机并出现错误(无法连接到本地主机端口 80:连接被拒绝)

我的 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

13
推荐指数
2
解决办法
2万
查看次数