I have faced some weird issue, I am sending request with Postman (using raw body) and getting correct response, but When I am making request with go, I am getting different response.
I tried this:
url := "http://example.com"
payload := strings.NewReader("key=value")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("content-type", "application/x-www-form-urlencoded")
req.Header.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36")
req.Header.Add("cache-control", "no-cache")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
But got wrong response, also tried using values
values := url.Values{}
values.Add("key", "value")
payload := strings.NewReader(values.Encode())
But still getting wrong response, is there a way to simulate postman's raw method in Go?
Postman is automatically adding cookies to my request, just added Cookie header and the problem is fixed