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