gpt4 book ai didi

http - Google App Engine Go HTTP Post []字节

转载 作者:IT王子 更新时间:2023-10-29 01:40:19 26 4
gpt4 key购买 nike

我想在 Go 中通过 Google App Engine 上的帖子通过 http 发送 []byte 数据。我如何构造 bodyType and, body为了请求?

最佳答案

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)
}
}

关于http - Google App Engine Go HTTP Post []字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7984931/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com