"use strict";
const fs = require("fs");
const request = require("request");
// Simple GET
request("http://localhost:14519/Test/GetHtml", (err, resp, body) => {
console.log("err: " + err);
console.log("statusCode: " + resp.statusCode);
console.log("body: " + body);
});
// Output GET results to file
request("http://localhost:14519/Test/GetJson").pipe(fs.createWriteStream("result.json"));
// POST with form parameters
request.post({
url: "http://localhost:14519/Test/PostParams",
form: { name: "John Smith" },
}, (err, resp, body) => {
console.log("err: " + err);
console.log("statusCode: " + resp.statusCode);
console.log("body: " + body);
});
// POST with JSON body
const options = {
method: "POST",
url: "http://localhost:14519/Test/PostJson",
json: { Name: "John Smith", Age: 34 }
};
const callback = (err, resp, body) => {
console.log(body);
};
request(options, callback);
// POST with JSON body and JSON result
request.post({
url: "http://localhost:14519/Test/PostJsonGetJson",
json: { Name: "Jack Doe", Age: 19 }
}, (err, resp, body) => {
console.log("NAME: " + body.Name);
console.log("AGE: " + body.Age);
console.log("Content Type: " + resp.headers["content-type"]);
});
Like this:
Like Loading...
Related