登录 主页

windows sthp 的使用,解决 curl: (7) Failed to connect to 127.0.0.1 port 8076 after 0 ms: Couldn't connect to server 的问题

2025-12-18 11:13AM

我的环境windows,安装了wsl(linux)

我安装了sthp之后,在powershell里面启动了sthp

 $ .\sthp-windows.exe -s 127.0.0.1:1078 -p 8076

 在wsl中添加了一个文件 ~/env_source_env,内容如下

 export HTTP_PROXY="http://127.0.0.1:8076"
 export HTTPS_PROXY="http://127.0.0.1:8076"
 export http_proxy="http://127.0.0.1:8076"
 export https_proxy="http://127.0.0.1:8076"

运行 source ~/env_source_env 命令

使用curl google,发现了失败了

$ curl google.com

curl: (7) Failed to connect to 127.0.0.1 port 8076 after 0 ms: Couldn't connect to server 

失败原因

windows 10 的 127.0.0.1仅限于windows里面使用,在wsl配置127.0.0.1,那么这个127.0.0.1是只属于linux中的127.0.0.1

在wsl里面使用 telnet 测试一下

$ telnet 127.0.0.1 8076
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

解决方法:

1. 查看 windows 的 ipconfig

 ipconfig

Windows IP 配置


以太网适配器 以太网:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :

无线局域网适配器 本地连接* 1:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :

无线局域网适配器 本地连接* 10:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :

无线局域网适配器 WLAN:

   连接特定的 DNS 后缀 . . . . . . . :
   ....
   IPv4 地址 . . . . . . . . . . . . : 192.168.1.115
   ...

以太网适配器 蓝牙网络连接:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :

以太网适配器 vEthernet (WSL):

   连接特定的 DNS 后缀 . . . . . . . :
   ...
   IPv4 地址 . . . . . . . . . . . . : 172.19.1.2
   ...

 可以发现 192.168.1.115 和 172.19.1.2 都是 windows 的ip地址

重新启动 sthp

$ .\sthp-windows.exe -s 127.0.0.1:1078 -p 8076 --listen-ip=0.0.0.0

增加 --listen-ip 实现可以使用 192.168.1.115 和 172.19.1.2 的IP地址

修改 wsl 的 ~/env_source_env

 export HTTP_PROXY="http://192.168.1.115:8076"
 export HTTPS_PROXY="http://192.168.1.115:8076"
 export http_proxy="http://192.168.1.115:8076"
 export https_proxy="http://192.168.1.115:8076"

重新运行 source ~/env_source_env 命令

再使用 curl google.com,发现就可以了

$ curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

返回>>

登录

请登录后再发表评论。

评论列表:

目前还没有人发表评论