我试图使用Strawpoll.me API创建新的民意调查。
var poll = { title: 'test', options: [ '1', '2' ] };
var request = require('request');
request.post(
'https://strawpoll.me/api/v2/polls',
{
body: poll,
json: true
},
function (error, response, body) {
console.log(JSON.stringify(response, null, 2));
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
但是我无法创建新的民意调查。我收到“ statusCode”:307和空的身体。
StrawPoll文档:https://github.com/strawpoll/strawpoll/wiki/API
我该怎么办?谢谢!
最佳答案
添加此选项followAllRedirects: true,
var poll = { title: 'test', options: [ '1', '2' ] };
var request = require('request');
request.post({
url: 'https://strawpoll.me/api/v2/polls',
followAllRedirects: true, // <----
body: poll,
json: true
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
响应:
{ id: 10585477,
title: 'test',
options: [ '1', '2' ],
votes: [ 0, 0 ],
multi: false,
dupcheck: 'normal',
captcha: false }