【发布时间】:2018-11-30 04:43:46
【问题描述】:
我正在使用 ssh 创建到 EC2 实例的代理连接:
ssh -v -D 8123 ubuntu@some.ip.address
我编写了一个非常简单的 Go 程序来发出 http 请求:
package main
import (
"io/ioutil"
"net/http"
"os"
"log"
"fmt"
)
func main(){
resp, err := http.Get("http://example.com")
if err != nil {
log.Println(err)
os.Exit(1)
}
fmt.Println(string(ioutil.ReadAll(resp.Body)))
}
当我正常运行我的程序时,它按预期工作。但是,当我使用 HTTP_PROXY env var(godoc、example)来指定一个 http 代理(或者如果我创建一个使用该代理进行传输的自定义 http 客户端)时,我会得到以下信息:
HTTP_PROXY=localhost:8123 ./main 2018/11/29 23:33:27 Get http://example.com: EOF
我建立代理的 SSH 会话的调试给了我:
debug1: Connection to port 8123 forwarding to socks port 0 requested.
debug1: channel 3: new [dynamic-tcpip]
debug1: channel 3: free: dynamic-tcpip, nchannels 4
当我将我的 macbook 的 wifi 适配器配置为使用 localhost:8123 作为 SOCKS 代理时,它似乎可以工作。我面向公众的 IP 地址发生了变化,流量似乎在流动(事实上,我现在正在使用它)。知道我的 Go 程序出现问题的原因吗?
【问题讨论】:
标签: go proxy network-programming http-proxy