Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how do i make http post in nodejs without third party

const https = require('https');
// it turns into flat json
var postData = JSON.stringify({
    'msg' : 'Hello World!'
});

var options = {
  hostname: 'posttestserver.com',
  port: 443,
  path: '/post.php',
  method: 'POST',
  headers: {
       'Content-Type': 'application/x-www-form-urlencoded',
       'Content-Length': postData.length
     }
};

var req = https.request(options, (res) => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);
  
  // getting the chunks of data
  res.on('data', (d) => {
    process.stdout.write(d);
  });
});

req.on('error', (e) => {
  console.error(e);
});

req.write(postData);
// we are done with request so we need to end
req.end();
Comment

PREVIOUS NEXT
Code Example
Javascript :: pass data from popup js 
Javascript :: map and get last child in js 
Javascript :: upload image in react next js authentication 
Javascript :: javascript condition based on table cell value 
Javascript :: typeorm with better sqlite using query builder 
Javascript :: typeorm caching queries time limit by id 
Javascript :: twitter user profile regex javascript 
Javascript :: javascript camel case to words 
Javascript :: response conditions 
Javascript :: create an array filled with 1 
Javascript :: node "promise.all" "retry" site:stackoverflow.com 
Javascript :: date change 
Javascript :: Example of Numeric Separators in es12 
Javascript :: Register post meta of sidebar in wordpress 
Javascript :: how to calculate time difference in js 
Javascript :: invert binary tree js 
Javascript :: lavania 
Javascript :: telegram web app js 
Javascript :: Show / Hide Div On Radio Button Click angular 
Javascript :: shipengine connect 
Javascript :: Safe Area View for android / Removing overflow of screen for android 
Javascript :: CalendarApp.newRecurrence 
Javascript :: react native image path in vriable 
Javascript :: substraction js 
Javascript :: adminlte 3 datatables reload 
Javascript :: disable find in page chrome through javascript 
Javascript :: Using DOM Nodes As Keys 
Javascript :: Render raw html in response with Express 
Javascript :: how to mask credit card number in javascript 
Javascript :: click to enlarge in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =