Last active
July 6, 2017 04:23
-
-
Save marciorodrigues87/a92c3a3e71ff9575678e2e818539d7c8 to your computer and use it in GitHub Desktop.
request-config-step-three.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Agent = require('agentkeepalive') | |
const httpAgent = new Agent({ | |
keepAlive: true, | |
maxSockets: 100 | |
}) | |
const zlib = require('zlib') // <-- | |
const request = require('request-promise').defaults({ | |
resolveWithFullResponse: true, | |
agent: httpAgent, | |
gzip: true | |
}) | |
const body = { | |
name: 'xxxxxx', | |
phone: '551141414455', | |
email: '[email protected]' | |
} | |
zlib.gzip(JSON.stringify(body), (err, gzip) => { | |
request.post({ | |
uri: 'http://www.mocky.io/v2/595da829100000cb007c1768', | |
headers: { | |
'content-encoding': 'gzip', // <-- | |
'content-type': 'application/json' // <-- | |
}, | |
body: gzip // <-- | |
}).then(response => { | |
console.log('statusCode:', response && response.statusCode) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment