doulie0178 2019-08-08 21:27
浏览 498

tls:HTTP请求上没有重新协商错误

I'm trying to make a simple HTTP request in Go, after directly following the guides I keep getting the same error:

local error: tls: no renegotiation

I don't quite understand how to interpret this? I know it's not an issue on the server as when I call the same request from python it returns fine. Here's my code:

package main

import (
    "fmt"
    "net/http"
    "net/url"
    "strings"
    "time"
)

func main() {
    timeout := time.Duration(20 * time.Second)
    client := &http.Client{
        Timeout: timeout,
    }
    data := url.Values{
        "top":   {"10"},
        "lDate": {"2019-01-01"},
    }
    req, err := http.NewRequest("POST", "https://api.*********.com/AppAvailLoads?", strings.NewReader(data.Encode()))
    if err != nil {
        fmt.Println("Error in construction")
    }
    req.Header.Add("x-cdata-authtoken", "********")
    req.Header.Add("content-type", "application/x-www-form-urlencoded")
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println("Error in request")
        fmt.Println(err)
    } else {
        fmt.Println(resp.Body)
        resp.Body.Close()
    }
}
  • 写回答

1条回答 默认 最新

  • duanhan9334 2019-08-08 23:02
    关注

    The solution was to to enable TLS renegotiation (go figure, I know), which is a constant that's part of the tls package as follows:

    tr := &http.Transport{
            TLSClientConfig: &tls.Config{
                Renegotiation:      tls.RenegotiateOnceAsClient,
                InsecureSkipVerify: true},
        }
    
    client := &http.Client{
            Timeout:   timeout,
            Transport: tr,
        }
    

    Which is weird, as no guides online explain this or show examples of how a common error such as local error: tls: no renegotiation occurs. I hope this is useful for people coming from other languages as it's not something one usually deals with!

    评论

报告相同问题?

悬赏问题

  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元