这更像是一个概念性的问题 - 所以请光临我.
问题:我收到了一个传入的HTTP请求到我的服务器应用程序.请求是这样的:http://xyz.com?id = abc.我需要解析此请求,修补其他URL参数并调用托管的html文件.所以:
http://xyz.com?id=abc => http://xyz.com:8080/temp.html?id=abc&name=cdf.
所以客户端应该看到temp.html
这是代码:
function onRequest(request,response) {
if(request.method =='GET') {
sys.debug("in get");
var pathName = url.parse(request.url).pathname;
sys.debug("Get PathName" + pathName + ":" + request.url);
var myidArr = request.url.split("=");
var myid = myidArr[1];
//Call the redirect function
redirectUrl(myid);
}
http.createServer(onRequest).listen(8888);
function redirectUrl(myid) {
var temp='';
var options = {
host: 'localhost',
port: 8080,
path: '/temp.html?id=' + myid + '&name=cdf',
method: 'GET'
};
var req = http.request(options, function(res) {
console.log('STATUS: …Run Code Online (Sandbox Code Playgroud)