grab
grab copied to clipboard
http: ContentLength=111 with Body length 0
I'm receiving an error while trying to download a file using POST, I've successfully done this with regular net/http. But the net/http is having issues with larger files, which is why I'm trying to move to this package. The error I'm receiving is on a file I was able to download successfully with net/http. I say another stackoverflow discussion that seems similar to my issue, but for another package, but not sure how to solve it in this package. Any help is appreciated. Link to other issue: https://stackoverflow.com/questions/52429036/getting-error-on-put-body-length-0-using-net-http
The error: http: ContentLength=111 with Body length 0
My code:
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{
Transport: transport,
}
site := fmt.Sprintf("https://%s/seg/api/v3/matrix/data/0/services-export", FSApplianceFQDN)
method := "POST"
//payload := strings.NewReader(`{"srcZoneId":"g_8973766297000773843","dstZoneId":"g_3554460426726078343","shouldOnlyShowPolicyViolation":false}`)
payloadFormat := fmt.Sprintf(`{"srcZoneId":"%s","dstZoneId":"%s","shouldOnlyShowPolicyViolation":false}`, SRCZone, DSTZone)
payload := strings.NewReader(payloadFormat)
req, err := http.NewRequest(method, site, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Host", FSApplianceFQDN)
req.Header.Add("Accept", "application/json, text/plain, */*")
req.Header.Add("Sec-Ch-Ua-Mobile", "?0")
req.Header.Add("Content-Type", "application/json;charset=UTF-8")
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36")
req.Header.Add("Sec-Fetch-Site", "same-origin")
req.Header.Add("Sec-Fetch-Mode", "cors")
req.Header.Add("Sec-Fetch-Dest", "empty")
req.Header.Set("referer", fmt.Sprintf("https://%s/forescout-client/", FSApplianceFQDN))
req.Header.Add("Accept-Encoding", "gzip, deflate")
req.Header.Add("Accept-Language", "en-US,en;q=0.9")
req.Header.Add("Connection", "close")
user := fmt.Sprintf("%%22%s%%22", FSusername)
Cookies := fmt.Sprintf("JSESSIONID=%v; user=%v; XSRF-TOKEN=%v", JSESSIONID, user, XSRFTOKEN)
req.Header.Set("Cookie", Cookies)
req.Header.Set("X-Xsrf-Token", XSRFTOKEN)
grabclient := &grab.Client{HTTPClient: client}
grabreq := &grab.Request{HTTPRequest: req}
filedownload := grabclient.Do(grabreq)
if err := filedownload.Err(); err != nil {
log.Fatal(err)
}