【问题标题】:Kannel HTTP POST failsKannel HTTP POST 失败
【发布时间】:2018-01-23 11:29:28
【问题描述】:

这是我的 NodeJS (request-promise),用于通过 HTTP GET 和 SMS 网关 Kannel 发送 SMS:

var options = {
    method: 'GET',
    uri: 'http://127.0.0.1:13002/cgi-bin/sendsms',
    qs: {
        username: 'foo',
        password: 'bar',
        to: '127883327304',
        from: '12488331359',
        text: 'Hi
    } 
};

这可行,但更改为 HTTP POST 失败。

var options = {
    method: 'POST',
    uri: 'http://127.0.0.1:13002/cgi-bin/sendsms',
    form: {
        username: 'foo',
        password: 'bar',
        to: '127883327304',
        from: '12488331359',
        text: 'Hi
    } 
 };

获取body: 'Authorization failed for sendsms' } }

也可以得到:body: 'Invalid content-type' } }

但是内容类型是正确的http形式:application/x-www-form-urlencoded

...并尝试了老式 XML:

var xml = ' \
<?xml version="1.0"?>\
<message>\
  <submit>\
    <da><number>11021034235</number></da>\
    <oa><number>11076034723</number></oa>\
    <ud>Hello</ud>\
    <from>\
      <user>foo</user>\
      <username>foo</username>\
      <pass>bar</pass>\
      <password>bar</password>\
    </from>\
  </submit>\
</message>\
';
var options = {
  method: 'POST',
  uri: 'http://127.0.0.1:13002/cgi-bin/sendsms',
  body: xml,
  headers: {'content-type': 'text/xml'}
};

但得到:body: 'Authorization failed for sendsms' } }

我不知道该怎么做,而且 HTTP GET 不适用于长 SMS。

【问题讨论】:

  • 您是否尝试过在查询字符串中传递usernamepassword,其余的使用form
  • 在不了解您后端的身份验证策略的情况下,我们应该如何回答您的问题?
  • 对不起,我正在运行 Kannel.org。
  • 将用户名和密码添加到查询 URL 不会改变任何东西 :(
  • 查看 Kannel 的 contrib-folder 中的所有示例都使用 HTTP GET,对于长 SMSes 失败。

标签: node.js kannel


【解决方案1】:

试过

request({
url: 'http://127.0.0.1:13002/cgi-bin/sendota',
method: 'POST',
headers : {
    'content-type': 'text/xml',
    'X-Kannel-Username': 'foo',
    'X-Kannel-Password': 'bar',
    'X-Kannel-To': '1324422133',
    'X-Kannel-From': '12023455750'
},
body: xml
}, function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});

现在我得到了正文:不支持的内容类型,被拒绝 但是应该支持 text/xml...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2017-12-19
    • 2017-05-16
    • 2012-12-11
    • 2016-04-29
    相关资源
    最近更新 更多