We are building up a large amount of data to be posted to a server, using a multipart form.
This is not an image, but a text field
Problem is it seems to get stuck at
`res, err := client.Do(req)
If I use a smaller byte array it works perfectly, but when it gets too large the POST never happens.
I hope this is not too vague
func postData(data *[]byte, host string) bool {
var b bytes.Buffer
w := multipart.NewWriter(&b)
// Add the field
fw, err := w.CreateFormField("data");
if err != nil {
return false
}
if _, err = fw.Write((*data)[:]); err != nil {
return false
}
// Don't forget to close the multipart writer.
// If you don't close it, your request will be missing the terminating boundary.
w.Close()
// Now that you have a form, you can submit it to your handler.
req, err := http.NewRequest("POST", host, &b)
if err != nil {
return false
}
// Don't forget to set the content type, this will contain the boundary.
req.Header.Set("Content-Type", w.FormDataContentType())
// Submit the request
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
return false
}
fmt.Println(res.StatusCode)
// Check the response
if res.StatusCode != http.StatusOK {
err = fmt.Errorf("bad status: %s", res.Status)
}
return true
}
Code was hacked from an example at http://stackoverflow.com/questions/20205796/golang-post-data-using-the-content-type-multipart-form-data