Как прочитать информацию в теле ответа из POST запроса? Ответ должен приходить в виде html как будто.
Больше 10 часов не могу раскодировать или что с ним надо делать. Читаю в инете и не нахожу. Вот в каком виде приходит resp.Body:
И вот то же самое на Python:
Вот код на Golang:
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"strings"
//"math/rand"
//"time"
)
func main() {
MakeRequest("https://www.investing.com/instruments/Service/GetTechincalData")
}
func MakeRequest(myUrl string) {
fmt.Println("URL:>", myUrl)
form := url.Values{}
form.Add("pairID","1062537")
form.Add("period","3600")
form.Add("viewType","normal")
req, err := http.NewRequest("POST", myUrl, strings.NewReader(form.Encode()))
req.Header.Set("User-Agent","Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0")
req.Header.Set("X-Requested-With", "XMLHttpRequest")
req.Header.Set("Accept", "text/html")
req.Header.Set("Accept-Encoding", "gzip, deflate")
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println("response Body:", string(body))
}
Accept-Encoding: gzip
, то оно не будет декодировано автоматически. либо укажитеAccept-Encoding:*