我正在构建一个Android应用程序的后端,该应用程序在服务器端使用nodejs,android应用程序向服务器发出带有所需参数的POST请求,服务器被禁止进行处理并将响应发送给服务器请求用户作为SMS.I有一个事务性SMS网关API,它完美地发送SMS作为来自浏览器的GET请求。但是相同的API在使用请求模块向节点脚本中的API发出GET请求时不发送SMS。 ..
以下是我的代码,请建议我哪里出错..
var express = require('express');
var request = require("request");
var bodyParser = require('body-parser');
var app = express();
var userName = "myUserName";
var passWord = "myPassWord";
var senderID = "mySenderID";
var content;
var from_number;
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.get('/', function(request, response) {
response.send('We Dont Reply for GET/,make a POST/ instead..');
});
app.post('/',
bodyParser.urlencoded({ extended: true }),
function(req, res) {
content = req.body.content; //Parameters passed as POST Request from my Android App
from_number = req.body.from_number;
console.log('making request to offlinebrowser-web with URL as ' + content + ' and sender as ' + from_number );
request("http://offlinebrowser-web.appspot.com/ExtractServlet?url=http://"+content+"&OutputType=1&ExtractorType=1", function(error, response, data) {
console.log('backend response : ' + data); //logs to console the valid output of GET Request
console.log('initiating response module');
request("**3.*5.*4.1*9/api/v3/sendsms/plain?user="+userName+"&password="+passWord+"sZd5y6AA&sender="+senderID+"&SMSText="+data+"&type=longsms&GSM="+from_number, function(error, response, body)
//making a GET request to the above link in browser,perfectly sends an SMS,but here doesnt work!
{
console.log(body); //this line logs undefined to the console
});
res.status(200).end();
});
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
答案 0 :(得分:0)
我已经通过在API URI前加上http://
来解决这个问题