douwu8524 2018-11-30 04:43
浏览 1946
已采纳

通过代理请求时的“ EOF”

I'm using ssh to create a proxy connection to an EC2 instance:

ssh -v -D 8123 ubuntu@some.ip.address

and I've written a very simple Go program that makes http requests:

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)))

}

When I run my program normally, it works as expected. However, when I use the HTTP_PROXY env var (godoc, example) to specify an http proxy (or if I make a custom http client that uses that proxy for transport), I get the following:

HTTP_PROXY=localhost:8123 ./main 2018/11/29 23:33:27 Get http://example.com: EOF

and the debug for my SSH session where I've established the proxy gives me:

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

When I configure my macbook's wifi adapter to use localhost:8123 as a SOCKS proxy, it appears to work. My public-facing IP address changes, and traffic seems to flow (in fact, I'm using it now). Any idea why my Go program is having problems?

  • 写回答

1条回答 默认 最新

  • duanfa2014 2018-11-30 05:23
    关注

    socks -D creates a SOCKS proxy. In your test you set a HTTP proxy. SOCKS proxy and HTTP proxy use different protocols, which means the request your client makes does not fit into what the proxy expects and thus it fails.

    For using a SOCKS proxy with Go see Creating a go socks5 client.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探