第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 PUT 方法在 Golang http 客戶端請求中未設(shè)置 Content-Length 標(biāo)頭

使用 PUT 方法在 Golang http 客戶端請求中未設(shè)置 Content-Length 標(biāo)頭

Go
阿晨1998 2021-10-25 20:30:37
我正在使用 Golang 1.4.2(從源代碼構(gòu)建),當(dāng)我嘗試通過 http.Client.Do() 發(fā)出 HTTP PUT 請求時,請求中缺少 Content-Length 標(biāo)頭。我所有的其他標(biāo)題都被發(fā)送了......我做錯了什么嗎?當(dāng)我通過 CURL 發(fā)出相同的請求時,將發(fā)送內(nèi)容長度標(biāo)頭。我的請求是向 etcd 服務(wù)器發(fā)出的,該服務(wù)器將我的所有鍵設(shè)置為空值。雖然這有點(diǎn)新穎,但幾乎沒有用。:)http://play.golang.org/p/pIoB--bXUTpackage mainimport (    "bytes"    "fmt"    "net/http"    "net/http/httputil"    "net/url"    "strconv")func main() {    put := url.Values{}    put.Set("value", "WHOAH here is my stuff")    put.Add("ttl","")    encode := put.Encode()    req, _ := http.NewRequest("PUT", "http://localhost:2379/v2/keys/somekey", bytes.NewBufferString(encode))    req.Header.Add("Content-Type", "application/x-www-form-urlencoded")    req.Header.Add("Content-Length", strconv.Itoa(len(encode)))    req.Header.Add("X-Content-Length", strconv.Itoa(len(encode)))    dump, _ := httputil.DumpRequest(req, true)    fmt.Println(string(dump))}產(chǎn)量PUT /v2/keys/somekey HTTP/1.1Host: localhostContent-Type: application/x-www-form-urlencodedX-Content-Length: 33ttl=&value=WHOAH+here+is+my+stuff
查看完整描述

2 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個贊

我對沒有發(fā)送 Content-Length 的說法不正確,我只是在使用 httputil.DumpRequest 時沒有看到它。

這里的解決方案是使用 httputil.DumpRequestOut 正確顯示 Content-Length 標(biāo)頭(和其他)。這意味著我的程序還有其他事情導(dǎo)致 etcd 設(shè)置空值。如果我弄清楚了,我也會使用該解決方案進(jìn)行更新。


查看完整回答
反對 回復(fù) 2021-10-25
?
長風(fēng)秋雁

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個贊

如果您說Content-Length未設(shè)置標(biāo)頭(實(shí)際上它是自動設(shè)置的,只是在轉(zhuǎn)儲時未顯示),它會按設(shè)計(jì)工作,因?yàn)?code>httputil.DumpRequest()即使您明確設(shè)置以下標(biāo)頭,它們也被排除在外:

  • Host

  • Content-Length

  • Transfer-Encoding

  • Trailer

線317go/src/net/http/httputil/dump.go。

如果您確實(shí)發(fā)送請求而不是轉(zhuǎn)儲它,您將看到Content-LengthUser-Agent和一起發(fā)送的標(biāo)頭Accept-Encoding


查看完整回答
反對 回復(fù) 2021-10-25
  • 2 回答
  • 0 關(guān)注
  • 568 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號