使用Node创buildStrawPoll.me轮询
我正在尝试使用Strawpoll.me API创build一个新的民意调查。
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 }