go - 如何不在 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
}
解决方案
推荐阅读
- python - 如何在一小时的数据框熊猫中找到平均值和最大值?
- javascript - 如何检查样式是否在元素上定义而不是继承?
- java - Java:是否可以对其实现类的客户端隐藏超级接口?
- excel - 如何使用 Powershell 关闭特定的 Excel 文件
- java - 为什么来自消息源的自定义消息不适用于请求参数验证?
- java - 无法在表单标签之外显示验证消息
- mysql - 如何在 SQL 中添加此约束?
- rasa-nlu - 有没有办法让我的 rasa 聊天机器人知道登录用户的全名并向他打招呼?
- android - 如何使用服务(Android 9)为 Wear os 上的所有应用设置样式资源
- ruby-on-rails - rails rack 攻击将请求限制为每个经过身份验证的用户每小时 N 个请求