首页 > 解决方案 > 如何不在 http 客户端中应用代理设置

问题描述

出于某种原因,我必须在 GoLand 设置中设置代理,有趣的部分是 Go 程序会自动应用代理,这是不应该的,解决方案 A 是No proxy在 GoLand 中设置,但不太优雅,我想知道如何告诉 go 程序不要为 http 客户端程序化应用任何代理,在此先感谢

func (r *RPC) Call(path string, request interface{}) []byte {
    url := fmt.Sprintf("%s%s", host, path)
    marshal, err := json.Marshal(request)
    if err != nil {
        return nil
    }
    newRequest, err := http.NewRequest("POST", url, bytes.NewBuffer(marshal))
    if err != nil {
        return nil
    }
    newRequest.Header.Set("Content-Type", "application/json")
    c := &http.Client{Timeout: time.Second}
    do, err := c.Do(newRequest)
    if err != nil {
        return nil
    }
    defer do.Body.Close()
    all, err := ioutil.ReadAll(do.Body)
    if err != nil {
        return nil
    }
    return all
}

标签: goproxy

解决方案


推荐阅读