Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

请问如何POST cnode社区的api?

$
0
0
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('响应中已无数据');
    })
  })
}```
无响应

Viewing all articles
Browse latest Browse all 14821

Trending Articles