【发布时间】:2018-05-26 02:05:02
【问题描述】:
我正在从节点服务器向其他服务器发送请求,但我需要发送内容类型
应用程序/json
如何发送,我正在使用这种格式
request.post('https://server.com/index.php/rest/V1/integration/admin/token',{form:postData},function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
res.json({
'error': error,
'statusCode': response && response.statusCode,
'body': body
})
});
我在尝试这个时遇到错误
request.post(
'https://server.com/index.php/rest/V1/integration/admin/token',
{
form:postData,
headers:{
"Content-Type": "application/json"
}
},function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
res.json({
'error': error,
'statusCode': response && response.statusCode,
'body': body
})
});
"message":"服务器无法理解 Content-Type HTTP 标头媒体 输入 application/x-www-form-urlencoded"
【问题讨论】:
-
文档中有一些内容类型的示例:github.com/request/request
-
当你提供一个key json它会自动设置内容类型application/json
-
@ManjeetThakur 但我收到此错误“服务器无法理解 Content-Type HTTP 标头媒体类型应用程序/x-www-form-urlencoded”,如果我设置,我可以从邮递员发布数据应用程序/json
-
可以发一下邮递员的图片你是怎么用的吗
标签: javascript node.js request