在运行 Webots 仿真项目时,控制器 Python 脚本需要访问 https://raw.githubusercontent.com
等国外资源,而我位于中国,尽管能“翻墙”,但 Webots 无法正常下载资源,提示 404
或连接超时。
通过配置 v2rayN 的 HTTP 代理功能,让 Webots 和其他命令行程序(如 curl
, pip
)能够使用代理访问外网。
-
Webots 启动时报错:无法访问
raw.githubusercontent.com
。 -
PowerShell 中
curl
命令访问 Google 报错:curl: (7) Failed to connect to 127.0.0.1 port 10809: Connection refused
- 打开 v2rayN,切换服务器节点,能浏览 Google/YouTube。
- 系统设置中未生效 HTTP 代理,命令行依旧无法代理访问。
在 v2rayN 界面中:
-
右键点击正在使用的服务器节点
-
选择:
属性 (服务器配置)
→设置本地端口
-
勾选并设置:
- 本地 Socks 代理端口(通常为
10808
) - 本地 HTTP 代理端口(如
10809
)
- 本地 Socks 代理端口(通常为
此时 HTTP 代理端口应为 127.0.0.1:10809
curl https://www.google.com --proxy http://127.0.0.1:10809
- 初期返回错误:
Connection refused
- 查看 v2rayN 日志,发现 HTTP 请求
malformed
,代理未监听 10809 端口 - 检查实际 Xray 核心路径,发现 v2rayN 可能调用的是
~/Downloads/.../v2rayN-windows-64/bin/xray/xray.exe
,而非我以为的旧路径
-
进入路径:
~/Downloads/v2rayN-windows-64-desktop/v2rayN-windows-64/bin
-
创建
myconfig.json
内容如下(简化版,仅启用 HTTP 和 Socks):
{
"inbounds": [
{
"port": 10808,
"listen": "127.0.0.1",
"protocol": "socks",
"settings": { "udp": true }
},
{
"port": 10809,
"listen": "127.0.0.1",
"protocol": "http",
"settings": {}
}
],
"outbounds": [
{
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "your_server_address",
"port": 12345,
"users": [{ "id": "uuid", "alterId": 0 }]
}
]
}
}
]
}
- 启动 Xray 手动运行该配置:
.\bin\xray\xray.exe run -c .\binConfigs\myconfig.json
- 验证是否成功:
curl https://www.google.com --proxy http://127.0.0.1:10809
🎉 出现 Google 页面 HTML 内容,说明 HTTP 代理生效!
@echo off
setlocal
echo 启动 Xray 核心...
start "" /min "%~dp0\bin\xray\xray.exe" run -c "%~dp0\binConfigs\myconfig.json"
set http_proxy=http://127.0.0.1:10809
set https_proxy=http://127.0.0.1:10809
echo 启动 Webots...
start "" "C:\Program Files\Webots\msys64\mingw64\bin\webots.exe"
endlocal
- 成功启用 v2rayN 的 HTTP 代理功能
curl
,pip
, Webots 等命令均可通过 HTTP 代理访问外网资源- 问题解决 ✅
环节 | 关键操作 |
---|---|
识别核心 | 查明 v2rayN 实际调用的 Xray 路径 |
启用 HTTP 代理 | 修改配置或手动启动核心并监听 10809 端口 |
验证代理功能 | 使用 curl --proxy 测试访问 Google |
自动化启动 | 编写 .bat 脚本一键设置代理 + 启动 Webots |
如果你希望我将这份文档导出为 Markdown 或 PDF,也可以告诉我。是否需要?