How can I make an outbound HTTP POST request, with data, in node.js?
相关问题
- Angular RxJS mergeMap types
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- HTML form is not sending $_POST values
- Google Apps Script: testing doPost() with cURL
- How to instantiate Http service in main.ts manuall
I use Restler and Needle for production purposes. They are both much more powerful than native httprequest. It is possible to request with basic authentication, special header entry or even upload/download files.
As for post/get operation, they also are much simpler to use than raw ajax calls using httprequest.
You can use request library. https://www.npmjs.com/package/request
To post JSON data:
To post xml data:
If you are looking for promise based HTTP requests, axios does its job nicely.
or you can you another library :
Posting another axios example of an axios.post request that uses additional configuration options and custom headers.
You can also use Requestify, a really cool and simple HTTP client I wrote for nodeJS + it supports caching.
Just do the following: