http (client and server requests)
Provides http client requests to remote server and request-response objects for (Fast)CGI calls.
Usage:
var http=require("http");
Making client request (GET):
var http=require("http");
var req=new http.ClientRequest("https://google.com/");
var resp=req.send(true);
system.stdout.writeLine("Response status is:"+resp.status);
system.stdout.writeLine("Response is:");
system.stdout.writeLine(resp.data.toString("utf-8"));
Making client request (POST):
var http=require("http");
var req=new http.ClientRequest("https://google.com/");
req.header({"User-Agent":"My Agent"});
req.method="POST";
req.post={
"login":"bbb",
"password":"ddd"
};
var resp=req.send(true);
system.stdout.writeLine("Headers are:");
var resp_h=resp.headers();
for (var k in resp_h) {
system.stdout.writeLine(" "+k+"="+resp_h[k]);
}
system.stdout.writeLine("Response is:");
system.stdout.writeLine(resp.data.toString("utf-8"));
Server-side:
function T(text)
{
return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
}
var html=[];
html.push("<html><body>");
html.push("<h1>Request method is "+request.method+"</h1>");
var args=request[request.method.toLowerCase()];
html.push("<h2>Arguments are:</h2>")
for (var k in args) {
html.push("<p>"+T(k)+"="+T(args[k])+"</p>");
}
html.push("</body></html>");
response.status(200);
response.header({"Content-Type":"text/html"});
response.write(html.join("\n"));
List of classes
Name | Description |
---|---|
ClientRequest | |
ClientResponse | |
ServerRequest | |
ServerResponse |
List of methods of ClientRequest
Name | Arguments | Returns | Description |
---|---|---|---|
new | String url | ClientRequest | |
header | Object | ||
send | Boolean follow | ClientResponse | |
setSkipPort
|
Boolean | void | |
setTimeout
|
Int | void | Sets timeout in milliseconds. |
setCertificateCheck
|
Boolean | void | Function to (dis)able ceftificate check. False to disable, True to enable. Default is True. |
setTLSMethod
|
Int | void | Set argument to 769-772 to enable TLS1.0-TLS1.3 respectively, default is TLS1.3. |
setSNI
|
String | void | Sets SNI, by default taken from url, to disable provide empty string. |
addParams
|
Map | void | Adds params to body. |
addFiles
|
Map | void | Adds file contents to body. |
|
List of methods of ClientResponse
Name | Arguments | Returns | Description |
---|---|---|---|
new | Buffer response | ||
header | |||
headers |
List of methods of ServerRequest
Name | Arguments | Returns | Description |
---|---|---|---|
new | Buffer data,Object headers | ||
headers | Object | ||
header | String key | String | |
List of methods of ServerResponse
Name | Arguments | Returns | Description |
---|---|---|---|
new | Buffer output, Object headers | ||
write | |||
cookie | |||
header | |||
status |