I am doing a request to a https based API.
When entering the request URL in Chrome, everything works fine. When doing the same request using the net/http
package in Go, I get an error about missing subdomain:
"error": {
"type": "ApiUnknown",
"message": "No api specified (via subdomain)"
}
I assume Chrome and Go somehow sends slightly different http requests, so, I need to know what those differences might be.
In Chrome I can use the Developer tools to see the sent request.
How can I get the HTTP request body being sent from the http
package?
I can do the following:
package main
import (
"net/http"
"os"
)
func main() {
urlStr := "https://api-name.subdomain.domain.org/page?param=value"
//client := &http.Client{}
req, err := http.NewRequest("GET", urlStr, nil)
if err != nil {
panic(err)
}
req.Write(os.Stdout) // Will this output be equal to the one being sent to the server?
//resp, err := client.Do(req)
}
Output:
GET /page?param=value HTTP/1.1
Host: api-name.subdomain.domain.org
User-Agent: Go 1.1 package http
Playground: http://play.golang.org/p/Oku0O1yiBt
But I am not sure whether the Transport adds something before the request is sent, or if this is actually all there is.