dongshipang8094 2019-01-14 11:55
浏览 102

我尝试通过http / https代理创建代理到代理的应用程序,但是我从没得到回应

I'm trying write rotating proxy on golang. there are no problems when proxying http: copied the client's request and forwarded it. But when I want to forward https - I can not read the request body, since it is encrypted. I learned that with the help of HTTP CONNECT, it is possible to create the tcp tunnel, but I cannot get the third-party proxy server to work. My scheme of work should be like this: 1) client -> 2) my proxy server -> 3) third-party proxy server -> 4) the site that the client wants but for now I'm stuck between 2 and 3 Can anyone help me?

i get this code as example https://github.com/hkwi/https_tproxy/blob/master/main.go

func handle(con net.Conn) {
    defer con.Close()

    req := &http.Request{
        Method: "CONNECT",
        Host:   con.LocalAddr().String(),
        URL:    &url.URL{},
    }

    conOut, err := net.DialTimeout("tcp", "EXTERNALPROXYIP:8080", 2*time.Second)
    if err != nil {
        log.Printf("proxy error %v", err)
    }
    defer conOut.Close()

    if err := req.WriteProxy(conOut); err != nil {
        log.Printf("proxy error %v", err)
    } else if res, err := http.ReadResponse(bufio.NewReader(conOut), req); err != nil {
        log.Printf("proxy error %v", err)
    } else if res.StatusCode != 200 {
        log.Printf("proxy error %v", err)
    } else {
        sent := make(chan bool)
        go func() {
            _, err := io.Copy(conOut, con)
            if err != nil {
                log.Printf("proxy error %v", err)
            }
            close(sent)
        }()
        _, err := io.Copy(con, res.Body)
        if err != nil {
            log.Printf("proxy error %v", err) ------> ERROR
        }
        _ = <-sent
    }

}

i have issue proxy error invalid byte in chunk length

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法