【问题标题】:Create StrawPoll.me poll with Node使用 Node 创建 StrawPoll.me 投票
【发布时间】:2016-10-23 08:53:40
【问题描述】:

我正在尝试使用 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

我能用它做什么?谢谢!

【问题讨论】:

  • 请在问题中包含所有相关代码,而不仅仅是链接到它,因为链接可能会腐烂..

标签: javascript node.js api post request


【解决方案1】:

添加此选项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 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-04
    • 2014-03-26
    相关资源
    最近更新 更多