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.
Example
var url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=chengdu&key= Aizasyadem01jiuaqddzqagjdy41ep6sbhxbl8s ";
var http = require (' http ')
var opt = {
Host: ' 127.0.0.1 ',
Port: ' 8087 ',
Method: ' Get ',//Here is the way to send
Path:url,//This is the path to access
headers:{
' Accept-language ': ' zh-cn,zh;q=0.8 ',
' Host ': ' maps.googleapis.com '
}
}
Here is the code that accepts the data
var body = ';
var req = http.request (opt, function (res) {
Console.log ("Got response:" + Res.statuscode);
Res.on (' Data ', function (d) {
Console.log (d);
Body + = D;
}). On (' End ', function () {
Console.log (Res.headers)
Console.log (body)
});
}). On (' Error ', function (e) {
Console.log ("Got error:" + e.message);
})
Req.end ();
Nodejs send HTTP requests via proxy (request)