Server1.js
var data = querystring.stringify({
imageName: reqImgName
});
var options = {
host: 'localhost',
port: 4321,
path: '/image',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': data.length
}
};
server2.js
http.createServer(function(req, res){
var reqMethod=req.method;
var request = url.parse(req.url, true);
var pathName = request.pathname;
console.log('Path name is '+pathName);
if (reqMethod=='POST' && pathName == '/image') {
//here i need my server1 data..how can i get here.
}
}).listen(4321);
var postData = '';
req.on('data', function(datum) {
postData += datum;
});
req.on('end', function() {
//read postData
});
您没有收到任何发布数据,因为没有在server1.js中发送任何数据。尝试将一些数据写入请求正文
var req = http.request(options, function(res) {
});
req.write('data=somedata');
调试服务器2的另一种方法是使浏览器向/ image发起POST请求。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句