亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

Axios 和 fetch 在 Golang 中給出空映射,即使在 url 編碼時(添加了標頭)

Axios 和 fetch 在 Golang 中給出空映射,即使在 url 編碼時(添加了標頭)

Go
嚕嚕噠 2023-05-04 17:08:31
我正在使用 axios 發送 http 請求(我也使用了 fetch 但它給出了相同的結果)。axios.post("http://localhost:3000/login",            {                answer: 42            },            {                headers: {                    "Content-Type": "application/x-www-form-urlencoded",                },            })在我的 go 文件中,我正在記錄響應func post(req *http.Request, res http.ResponseWriter) {    req.ParseForm()    fmt.Println(req.Form)}日志如下:map[{"answer":42}:[]]但是我希望它如下所示:map["answer":[42]](當我使用郵遞員時我得到了這樣的信息)這有什么問題。出站數據供參考
查看完整描述

1 回答

?
慕婉清6462132

TA貢獻1804條經驗 獲得超2個贊

你需要這樣的東西:


var querystring = require('querystring');

axios.post('http://localhost:3000/login', querystring.stringify({'answer': 42},headers: {

? ? 'Content-Type': 'application/x-www-form-urlencoded'

});

您可以使用 params 配置選項設置查詢字符串參數,它肯定會起作用:


axios.post("http://localhost:3000/login", "", {

? ? params: {answer: 42},

? ? headers: {

? ? ? ? 'Content-Type': 'application/x-www-form-urlencoded'

? ? }

})

查看完整回答
反對 回復 2023-05-04
  • 1 回答
  • 0 關注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號