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 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法