本文介绍了如何使用Node.js进行外部HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题很简单。我想使用Node.js服务器作为代理来记录,验证和转发HTTP查询到后端HTTP服务器(PUT,GET和DELETE请求)。
The question is fairly simple. I want to use a Node.js server as a proxy to log, authenticate, and forward HTTP queries to a backend HTTP server (PUT, GET, and DELETE requests).
我应该为此目的使用哪个库?我恐怕找不到一个。
What library should I use for that purpose? I'm afraid I can't find one.
推荐答案
NodeJS支持http.request作为标准模块:
NodeJS supports http.request as a standard module:http://nodejs.org/docs/v0.4.11/api/http.html#http.request
var http = require('http');
var options = {
host: 'example.com',
port: 80,
path: '/foo.html'
};
http.get(options, function(resp){
resp.on('data', function(chunk){
//do something with chunk
});
}).on("error", function(e){
console.log("Got error: " + e.message);
});
这篇关于如何使用Node.js进行外部HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!