Guest User

Untitled

a guest
Apr 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. Api.prototype.execute = function(url, method, args, do_something_with_chunk) {
  2. if (url && method) {
  3. basicAuth = new Buffer(this._user+':'+this._apiKey).toString('base64');
  4. var http = require('http');
  5. var api = http.createClient(80, this._host);
  6. var request = api.request(method, this._url+url,
  7. { 'host': this._host, 'authorization': 'Basic '+basicAuth });
  8. request.end();
  9. request.on('response', function (response) {
  10. response.setEncoding('utf8');
  11. response.on('data', function (chunk) {
  12. do_something_with_chunk(chunk);
  13. });
  14. });
  15. } else {
  16. return false;
  17. }
  18. }
Add Comment
Please, Sign In to add comment