First, the local environment, not including the domain name method:
Https://www.npmjs.com/package/http-server (Reference manual)
How to use it correctly:
Second, the configuration method with the domain name:
https://cnodejs.org/topic/50d41da5637ffa4155f63179 and http://blog.csdn.net/yuan882696yan/article/details/25052469 (reference method)
Nodejs sends HTTP requests via Proxy (request):
Method One:
Request.post ({url:url,proxy: ' Http://username:[email protected]:8080 ', Oauth:oauth}
var options = {
Host: "Kws.proxy.nic.fujitsu.com",
port:8080,
Path:requestpath,
Headers: {
' Proxy-authentication ': ' Base ' + new Buffer ('username:password'). ToString (' base64 ')
}
};
var requrl = Request (url,{' proxy ': '//Username:password@kws. proxy.nic.fujitsu.com:8080 '});
Note: User name, password in the URL of the wording
Method Two:
There may be such a need, node as the Web server through another Http/https Proxy server http or HTTPS request, nonsense said directly on the code we all understand:
Varhttp= Require(' HTTP ')VarOpt= {Host:' Put the proxy server IP or domain name here ',Port:' Put the proxy server's port number here ',Method:' POST ',Here's how it's sent.Path:' Https://www.google.com ', Here is the path to accessHeaders:{ Here's the request header that you want to send out. }}Here is the code that accepts the dataVarBody= ‘‘;VarReq=http.Request(Opt, function(Res) {Console.Log("Got Response:" +Res.StatusCode);Res.On(' Data ',function(D){Body+=D; }).On(' End ', function(){Console.Log(Res.Headers)Console.log (body). on ( ' ERROR ' , function (e{ Console. ( "Got error:" + e< Span class= "pun". message); }) req.
This allows us to specify the proxy server to make HTTPS requests, note here we are the Proxy server is the HTTP protocol, not HTTPS, the results will certainly be different depending on your proxy server.
Building Local Service environment with Nodejs Http-server