[英]"axios.defaults.headers.common['Content-Type'] = 'application/json'" but axios.post still is "application/x-www-form-urlencoded"
[英]Unable to send JSON object over “Content-Type”: "application/x-www-form-urlencoded
有一个奇怪的问题。
我有一个 object
const otherParams = {
hello: "world"
};
const params = {
payload: JSON.stringify(otherParams);
apiKey: 1234,
hmac: 13414
}
我也使用了 npm package querystring
来编码params
// post method here
url: "https://endpoint.com",
method: "POST",
query: querystring.stringify(params),
headers: {
"Content-type": "application/x-www-form-urlencoded"
}
一切都很好,但问题是没有发送payload
,这是querystring
无法编码payload
的问题吗?
尝试使用
url: "https://endpoint.com",
method: "POST",
query: querystring.stringify(params),
headers: {
"Content-type": "application/x-www-form-urlencoded","application/json"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.