Created
November 5, 2014 03:59
-
-
Save jhummel/98639dd9ec70f5a2e0df to your computer and use it in GitHub Desktop.
Sample VIP Request in Node
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
var moment = require('moment'); | |
var http = require('http'); | |
var crypto = require('crypto'); | |
function makeRequest(callback) { | |
var secret = '<SHARED SECRET>' | |
var id = '<CLIENT ID>' | |
var params = 'action=brands' | |
var timestamp = moment.utc().format("ddd, D MMM YYYY HH:mm:00 [GMT]"); | |
var signature = timestamp + secret + params + id | |
var sha = crypto.createHash('sha256') | |
var encrypt = sha.update(signature).digest('hex') | |
return http.request({ | |
host: 'www.vtinfo.com', | |
path: '/PF/product_finder-service.asp?' + params, | |
headers: { | |
'vipCustID': id, | |
'vipTimestamp': timestamp, | |
'vipSignature': encrypt | |
} | |
}, function(response){ | |
var body = '' | |
response.on('data', function(d) { | |
body += d; | |
}); | |
response.on('end', function() { | |
console.log(body); | |
}); | |
}); | |
} | |
var req = makeRequest(); | |
req.on('error', function(e){ | |
console.log( "ERROR:" + e.message); | |
}); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment