POST request with data in node.js

How can I send a POST request with data (for example, some variables) to the https server and display the results for the end user?

+4
source share
1 answer

Use the http.Client module. From the docs:

 var http = require('http'); var google = http.createClient(80, 'www.google.com'); var request = google.request('GET', '/', {'host': 'www.google.com'}); request.end(); request.on('response', function (response) { console.log('STATUS: ' + response.statusCode); console.log('HEADERS: ' + JSON.stringify(response.headers)); response.setEncoding('utf8'); response.on('data', function (chunk) { console.log('BODY: ' + chunk); }); }); 

I'm sure you can exchange GET for POST ;)

+4
source

Source: https://habr.com/ru/post/1332340/


All Articles