How to use the post function from request
Find comprehensive JavaScript request.post code examples handpicked from public code repositorys.
request.post is a function in Node.js that sends an HTTP POST request to a specified URL with optional form data, JSON payload, or other options.
GitHub: cryptobuks/duniter
217 218 219 220 221 222 223 224 225 226
post(peer:any, uri:string, data:any) { if (!peer.isReachable()) { return Promise.resolve(); } return new Promise((resolve, reject) => { const postReq = request.post({ "uri": protocol(peer.getPort()) + '://' + peer.getURL() + uri, "timeout": this.timeout || constants.NETWORK.DEFAULT_TIMEOUT }, (err:any, res:any) => { if (err) {
30 31 32 33 34 35 36 37 38 39
newArticle.discuss = 0; newArticle.status = 0; return await this.articleRepository.save(newArticle).then(res => { if (process.env.DEV === 'production') { // 百度 seo push request.post({ url: `http://data.zz.baidu.com/urls?site=${process.env.BAIDU_PUSH_SITE}&token=${process.env.BAIDU_PUSH_TOKEN}`, headers: {'Content-Type': 'text/plain'}, body: `${process.env.BAIDU_PUSH_SITE}/article/${newArticle.id}`, }, (error, response, body) => {
+ 7 other calls in file
How does request.post work?
request.post is a function provided by the request library in Node.js used to send an HTTP POST request to a specified URL with optional form data, JSON payload, or other options. When request.post is called, it takes as input a URL string and an optional options object containing data, headers, authentication, and other configuration options. If the options object contains form data, it is encoded as a URL-encoded string and sent as the request body. If the options object contains a JSON payload, it is serialized as a JSON string and sent as the request body with a Content-Type header of application/json. The request.post function returns a http.IncomingMessage object that represents the server's response. This object provides methods for reading the response data and headers, as well as properties indicating the response status code and message. request.post also supports streaming and piping of request and response data, allowing for efficient handling of large files and streams of data. request.post is commonly used in Node.js applications to send data to a server, such as submitting a form, uploading a file, or interacting with an API. By providing a simple and flexible interface, request.post makes it easy to work with HTTP requests and responses in Node.js.
GitHub: mafintosh/polo
40 41 42 43 44 45 46 47 48 49
}); socket.on('close', function() { sockets--; Object.keys(hosts).forEach(function(host) { request.post(host + '/gc', noop); }); gc(); });
+ 3 other calls in file
150 151 152 153 154 155 156 157 158 159
[global.AUTH_NAME]: bkTicket, allow_overwrite: 'true' // 覆盖原有的源码包 } const url = `${v3Config.URL_PREFIX}/bkapps/applications/${appInfo.appCode}/modules/${appInfo.moduleCode}/source_package/link/` return new Promise((resolve, reject) => { request.post({ url, formData }, function (error, response, body) { if (!error && response.statusCode === 200) { resolve(body) } else { let res = {}
+ 2 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
const request = require("request"); const options = { url: "https://example.com/api", method: "POST", headers: { "Content-Type": "application/json", }, body: { name: "John Smith", age: 30, email: "john.smith@example.com", }, json: true, }; request.post(options, (error, response, body) => { if (error) { console.error(error); return; } console.log(response.statusCode); console.log(body); });
In this example, we first import the request module. We define an options object that contains the URL of the server, the HTTP method (in this case, POST), a Content-Type header indicating that the request body is JSON, and a JSON payload with some data. We set the json option to true to indicate that the payload should be serialized as JSON. We then call request.post with the options object and a callback function that will be called when the server responds. If there is an error, we log it to the console. Otherwise, we log the HTTP status code and the response body to the console. When we run the code, it will send a POST request to the specified URL with the JSON payload. The server will process the request and send a response, which will be logged to the console.
27 28 29 30 31 32 33 34 35 36
let user; let confirmation_code; describe('Register test', function() { it('should be successful', function(done) { request.post( { url: url('/api/auth/register'), json: sampleUser },
+ 13 other calls in file
GitHub: ctide/fakeweb
3 4 5 6 7 8 9 10 11 12
const http = require('http'); const utils = require('./utils'); const url = require('url'); const oldRequestGet = request.get; const oldRequestPost = request.post; const oldHttpsRequest = https.request; const oldHttpRequest = http.request; function createException() {
+ 9 other calls in file
GitHub: mojotech/pullr
64 65 66 67 68 69 70 71 72 73
prompt.message = ""; prompt.delimiter = ""; console.log(" Please Enter Your GitHub Credentails ".yellow.inverse); prompt.get(promptSchema, function(err, credentials) { request.post('https://api.github.com/authorizations', { headers : { 'User-Agent': 'Pullr NPM v'+package.version }, 'auth': {
+ 3 other calls in file
75 76 77 78 79 80 81 82 83 84
var self = this; var url = self._getUrl(UPLOAD_PATH) + '?' + self._getRequestQueryString(options); if (options.image) { // already got the raw image data, just post it request.post({ url: url, body: options.image }, callback); return; } if (!options.imagePath) {
+ 9 other calls in file
12 13 14 15 16 17 18 19 20 21
UnknowError: 127 } function postAsync(_path, json) { return new Promise((resolve, reject) => { request.post(`${secret.pixivpyUrl}${_path}`, { json }, (err, res, body) => { if (err || body.code != 0) { if (body.code == -1) reject(errorCode.LoginFail);
146 147 148 149 150 151 152 153 154
form: { response: captchaResponse, secret: secret } }; request.post(postData, function (err, response, body) { if (err) { return done(err); }
GitHub: dbpedia/databus
34 35 36 37 38 39 40 41 42
"Accept": accept, "Content-type": "application/x-www-form-urlencoded" }, }; request.post(options).pipe(res); }); router.post('/api/publish', protector.protect(true), async function (req, res, next) {
+ 110 other calls in file
GitHub: lplotni/pace
36 37 38 39 40 41 42 43 44 45
it('allows to send finish times', (done) => { startBlocks.add('0','test Block'); participants.save(aParticipant) .then(() => { request.post({url: url, headers: headers, form: form}, (err, response) => { expect(response.statusCode).toBe(200); done(); }); })
+ 7 other calls in file
GitHub: ets-berkeley-edu/suitec
223 224 225 226 227 228 229 230 231 232
}, 'headers': { 'authorization': authorizationHeader } }; request.post(config.get('previews.url'), params, function(err, response, body) { if (err) { log.error({ 'err': err, 'id': id,
58 59 60 61 62 63 64 65 66 67
body: JSON.stringify(payload) }; process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; request.post(options, function(err, response, body) { // var loginString = printf("login -s " + config.server + " -u " + config.username + " -p '" + password + "' --realm " + config.realm); // call(loginString, config, function(err, stdout) { if (err) {
442 443 444 445 446 447 448 449 450 451
headers : { 'Authorization' : "Basic " + Buffer.alloc(self.options.username + ":" + self.options.password).toString('base64') } }; request.post(data, (err, resp, body) => { if (err) { callback(err); return; }
298 299 300 301 302 303 304 305 306 307
'Authorization': 'Basic ' + (new Buffer(serverData.clientID + ':' + serverData.clientSecret).toString('base64')) }, json: true }; request.post(authOptions, function(error, response, body) { if (!error && response.statusCode === 200) { var access_token = body.access_token, refresh_token = body.refresh_token;
+ 3 other calls in file
33 34 35 36 37 38 39 40 41 42 43
* @returns {Promise} Promise object represents the post body */ const postShopify = function(option) { return new Promise(function(resolve, reject) { request.post(option, function(err, res, body) { if (err) { reject(err); }
GitHub: za419/CadenceBot
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156
gzip: true, }; log.info("Making a request to " + url); log.debug("body=" + post.body); request.post(post, function (err, response, body) { log.info("Received response."); if ( !err && (!response ||
+ 9 other calls in file
GitHub: racker/node-buildbot
66 67 68 69 70 71 72 73 74
}; Buildbot.prototype.sendChanges = function(options, user, callback) { var body = this._sendChangesBody(options, user); var change_url = this.url(this._changeHookURL); request.post({uri: change_url, form: body}, function (error, response, body) { callback(error, response, body); }); };
766 767 768 769 770 771 772 773 774 775
} else { this.log.debug(body); this.log.error("No Token received visiting url and accept the permissions."); this.log.info(getRequest.uri.href); const form = this.extractHidden(body); getRequest = request.post( { url: getRequest.uri.href, headers: { "Content-Type": "application/x-www-form-urlencoded",
+ 10 other calls in file
request.get is the most popular function in request (2246 examples)