Google App Engine Go HTTP Post []字节 [英] Google App Engine Go HTTP Post []byte
本文介绍了Google App Engine Go HTTP Post []字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过Go上的Google App Engine上发布的[]字节数据发送数据。如何为请求构建 bodyType和body ?
I want to send []byte data over http via post on Google App Engine in Go. How do I construct bodyType and, body for the request?
推荐答案
package app
import (
"http"
"appengine"
"appengine/urlfetch"
"bytes"
"fmt"
)
func init() {
http.HandleFunc("/post", post)
}
func post(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
bs := []byte{1,2,3}
buf := bytes.NewBuffer(bs)
client := http.Client{Transport: &urlfetch.Transport{Context:c}}
if _, err := client.Post("http://localhost:8080/", "application/octet-stream", buf); err != nil {
fmt.Println(err)
}
}
这篇关于Google App Engine Go HTTP Post []字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文