我正在使用 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'
? ? }
})
- 1 回答
- 0 關注
- 138 瀏覽
添加回答
舉報
0/150
提交
取消