Skip to content

Instantly share code, notes, and snippets.

@marciorodrigues87
Last active July 6, 2017 04:23
Show Gist options
  • Save marciorodrigues87/a92c3a3e71ff9575678e2e818539d7c8 to your computer and use it in GitHub Desktop.
Save marciorodrigues87/a92c3a3e71ff9575678e2e818539d7c8 to your computer and use it in GitHub Desktop.
request-config-step-three.js
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: 'viva@vivareal.com'
}
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