'tls: no renegotiation error on HTTP request
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()
}
}
Solution 1:[1]
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,
// You may need this if connecting to servers with self-signed certificates
// 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!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ItalyPaleAle |