我试图使用 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 }
关于javascript - 使用 Node 创建 StrawPoll.me 民意调查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37950669/