var postData = JSON.stringify({
'accesstoken': 'xxxx',
})
var options = {
hostname: 'https://cnodejs.org',
path: '/api/v1',
port: 443,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
var req = https.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`主体: ${chunk}`);
});
res.on('end', () => {
console.log('响应中已无数据');
})
})
}```
无响应
回复 (6)
H
引用 zhanzhenzhen哎,为什么有这么多人喜欢把Content Type设为application/x www form urlencoded?JSON的Content Type是application/json。
@zhanzhenzhen 多谢帮助,诚如你所说和Content-Type有关
H
引用 jiangli373你没有写具体的请求地址吧 path: '/api/v1', 这和一楼说的Content Type没有什么关系
@jiangli373 多谢啦,搞定了
Z
哎,为什么有这么多人喜欢把Content-Type设为application/x-www-form-urlencoded?JSON的Content-Type是application/json。
J
你没有写具体的请求地址吧 path: '/api/v1',
这和一楼说的Content-Type没有什么关系
T
我记得有个request类库可以直接请求呀, 没必要写这么多吧
N
搞请求用superagent呀
参与回复
登录后即可参与回复。登录