Created
May 11, 2016 05:57
-
-
Save jonathaningram/d63103349f4433742ff26564531aa3e6 to your computer and use it in GitHub Desktop.
You can create an App Engine POST task with a JSON body as well as a form-encoded one. You just need to set the Payload and Content-Type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"net/http" | |
"google.golang.org/appengine/taskqueue" | |
) | |
// NewJSONPostTask creates a Task that will POST to a path with the given body | |
// encoded as JSON. | |
func NewJSONPostTask(path string, body interface{}) (*taskqueue.Task, error) { | |
h := make(http.Header) | |
h.Set("Content-Type", "application/json") | |
b, err := json.Marshal(body) | |
if err != nil { | |
return nil, err | |
} | |
return &taskqueue.Task{ | |
Path: path, | |
Payload: b, | |
Header: h, | |
Method: "POST", | |
}, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment