我有以下GET请求:
我想在node.js中获得响应。有人可以为我指出正确的方向吗?
提前谢谢了,
最佳答案
是代理吗?如果是这样,则可以使用以下代理:
var net = require('net');
// Create TCP-server
var server = net.createServer( function(soc){ // soc is socket generated by net.Server
// Incoming request processing
soc.on('data', function(data){
// Create new socket
var client = net.Socket();
// Get host from HTTP headers
var re = /[^\n]+(\r\n|\r|\n)host:\w*([^:\r\n]+)/i;
var host = data.toString('utf-8').match(re);
// Pause soc for inner socket connection
soc.pause();
// Connect to Node.js application
client.connect(80, host);
client.on('connect', function()
{
// Write request to your node.js application
client.write(data.toString('utf-8'));
});
client.on('data', function(cdata)
{
// Return socket to live
soc.resume();
// Write client data to browser
soc.write(cdata.toString('utf-8'));
soc.pipe(soc);
soc.end();
});
client.on('end', function(){
client.destroy();
});
});
}
);
server.on('error', function (err){
// Error processing i just pass whole object
console.log(err);
});
server.listen(8088);
console.log('Server is listening %d\n', 8088);
关于http - Node.js:应用 header 并获得响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7076609/