I'm having some trouble sending a simple POST request with the http package:
var http_client http.Client
req, err := http.NewRequest("POST", "http://login.blah", nil)
if err != nil {
return errors.New("Error creating login request: " + err.Error())
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
body := fmt.Sprintf("?username=%s&password=%s&version=%d", client.Username, client.Password, launcherVersion)
fmt.Println("Body:", body)
req.Body = ioutil.NopCloser(bytes.NewBufferString(body))
req.ParseForm()
resp, err := http_client.Do(req)
if err != nil {
return errors.New("Error sending login request: " + err.Error())
}
I see the correct body from the print:
Body: ?username=test&password=test&version=13
But after 60 seconds, I get:
Error sending login request: unexpected EOF
I'm sure it has something to do with how I set the request body, because watching it with Wireshark shows me the request, which goes out right away, has a Content-Length
of 0 with no body.
POST / HTTP/1.1
Host: login.blah
User-Agent: Go http package
Content-Length: 0
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip