I'm using Go, and I'm trying to place a task on the taskqueue which has some JSON encoded content in the body. However, I seem to be getting 301 responses, and it seems to be related to the Task.Payload.
The code that I'm using is structurally as the code below, with `am` being a struct with working JSON tags:
func QueueAdminMessage(ctx context.Context, am adminMessage) error {
// Encode the admin message.
rawMsg, err := json.Marshal(am)
if err != nil {
return err
}
task := &taskqueue.Task{
Path: endpoints.SendAdminMessage,
Payload: rawMsg,
Method: "POST",
}
newTask, err := taskqueue.Add(ctx, task, "admin-messaging")
if err != nil {
return err
}
log.Debugf(ctx, "New Task:\n Path: %s\n Payload:%s", newTask.Path, string(newTask.Payload))
return nil
}
This seems to add a task to the taskqueue, but the task constantly fails (with a 301 response). My guess is that I'm not setting the Payload up correctly, but I can't find very much on how to specify a body content with the payload. The documentation states (in reference to the Payload):
// Payload is the data for the task.
// This will be delivered as the HTTP request body.
// It is only used when Method is POST, PUT or PULL.
// url.Values' Encode method may be used to generate this for POST requests.
It says that the url.Values Encode method *may* be used, but not that it *must* be used.