How to use the request function from http
Find comprehensive JavaScript http.request code examples handpicked from public code repositorys.
GitHub: PubFork/miniblink49
![PubFork profile picture](/PubFork.png?size=40)
12 13 14 15 16 17 18 19 20 21
this.req = https.request(options); } else if (hasCrypto && "https:" == options.protocol) { this.req = https.request(options); } if (!this.req) this.req = http.request(options); } ClientRequest.prototype.on = function(evt, callback) { this.req.on(evt, callback);
+ 11 other calls in file
27 28 29 30 31 32 33 34 35 36
}) } // parse out the options from options.url var opts = url.parse(options.url) var method = opts.protocol === 'https:' ? https.request : http.request var defaultContentType = 'application/json; charset=utf-8' // check for additional query params if (options.data) {
347 348 349 350 351 352 353 354 355 356
+ maxSockets: 1 +}); + +function request(path, callback) { + const port = server.address().port; + const req = http.request({ agent, path, port }, common.mustCall((res) => { + assert.strictEqual(res.statusCode, 200); + + res.setEncoding('utf8'); +
GitHub: datacratic/node
![datacratic profile picture](/datacratic.png?size=40)
66 67 68 69 70 71 72 73 74 75
exports.request = function(options, cb) { if (options.agent === undefined) { options.agent = globalAgent; } return http.request(options, cb); }; exports.get = function(options, cb) { options.method = 'GET';
40 41 42 43 44 45 46 47 48 49
this.rpcReq.params = params || []; var postData = JSON.stringify(this.rpcReq); var timeoutHandle = null; var req = http.request({ method: 'POST', hostname: this.url, port: this.port, path: this.path,
7947 7948 7949 7950 7951 7952 7953 7954 7955 7956
result.query = relative.query; result.host = relative.host || ''; result.auth = relative.auth; result.hostname = relative.hostname || relative.host; result.port = relative.port; // to support http.request if (result.pathname || result.search) { var p = result.pathname || ''; var s = result.search || ''; result.path = p + s;
+ 24 other calls in file
449 450 451 452 453 454 455 456 457 458
// https if specified, fallback to http in any other case if (options.protocol == 'https:') { request = https.request(options); } else { request = http.request(options); } // get content length and fire away this.getLength(function(err, length) {
+ 10 other calls in file
GitHub: zimbora/rtls-controller
322 323 324 325 326 327 328 329 330 331
if(data.sector == "Office"){ var options = { host: '10.168.1.64', path: '/relay/0?turn=on' }; http.request(options, callback).end(); } //} }, }
GitHub: NataliaCalvo/Podcast
701 702 703 704 705 706 707 708 709 710
} } const defaultPort = isSecure ? 443 : 80; const key = randomBytes(16).toString('base64'); const request = isSecure ? https.request : http.request; const protocolSet = new Set(); let perMessageDeflate; opts.createConnection = isSecure ? tlsConnect : netConnect;
GitHub: mankyKitty/graph-dsl
138 139 140 141 142 143 144 145 146 147
headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': data.length } }; let request = http.request(options, (response) => { response.setEncoding('utf8'); let rawData = ''; response.on('data', (chunk) => { rawData += chunk; }); response.on('end', () => {
379 380 381 382 383 384 385 386 387 388
{ host: 'www.haus-bus.de', path: '/'+firmwareName+'.chk' }; http.request(options, function(response) { var str = ''; response.on('data', function (chunk) {str += chunk;}); response.on('end', function ()
29 30 31 32 33 34 35 36 37 38
if (req.query.user) { opt.path = opt.path + "&user=" + req.query.user; } console.log(opt.path); var body = ''; var request = http.request(opt, function (response) { console.log("Got response: " + response.statusCode); response.on('data', function (d) { body += d; }).on('end', function () {
32 33 34 35 36 37 38 39 40 41
hostname: 'ip-api.com', path: '/json', method: 'GET' }; const req2 = http.request(options, res2 => { let body = ''; res2.on('data', chunk => { body += chunk; });
143 144 145 146 147 148 149 150 151 152
(r) => { let buffers = []; r.on("data", (b) => buffers.push(b)); r.on("end", () => { const nonce = JSON.parse(Buffer.concat(buffers)).nonce; let req = http.request( { hostname: "acapela-group.com", port: "8080", path: "/webservices/1-34-01-Mobility/Synthesizer",
732 733 734 735 736 737 738 739 740
} if (self._aws) { self.aws(self._aws, true) } // We have a method named auth, which is completely different from the http.request // auth option. If we don't remove it, we're gonna have a bad time. var reqOptions = copy(self) delete reqOptions.auth
11 12 13 14 15 16 17 18 19 20 21 22
const jp = require('jsonpath'); const csv_stringify = require('csv-stringify/lib/sync'); const run_query = (query_options, filters, callback) => { let tic = () => 0.; http.request(query_options, function (res) { let body = '', ttfb = tic(); res.setEncoding('utf8'); res.on('data', function (chunk) {
297 298 299 300 301 302 303 304 305 306
You can start writing to the stream right away and the writes will be buffered until the `'connect'` event fires. ## net.createServer() ## http.request() ## http.createServer() ## zlib.createGzip()
http.createServer is the most popular function in http (322 examples)