Building Local Service environment with Nodejs Http-server

Source: Internet
Author: User
Tags oauth

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.