task

title

[previously]

  1. ] http://davidwalsh.name/nodejs-http-request

[currently]

  1. ]  

[next]

  1. ]

 

my subset

   var http =  require http

function getDrivers(cb) {
       http.get({
        host: 'sospep.com',
        path: '/qry/'
    }, function(res) {
        // explicitly treat incoming data as utf8 (avoids issues with multi-byte chars)
        res.setEncoding('utf8');
        // incrementally capture the incoming response body
        var body = '';
        res.on('data', function(d) {
            body += d;
        });
        // do whatever we want with the response once it's done
        res.on('end', function() {
            try {
                var parsed = JSON.parse(body);
            } catch (err) {
                console.error('Unable to parse response as JSON', err);
                return cb(err);
            }
            // pass the relevant data back to the callback
            cb(null, {
                email: parsed.email,
                password: parsed.pass
            });
        });
    }).on('error', function(err) {
        // handle errors with the request itself
        console.error('Error with the request:', err.message);
        cb(err);
    });
}
 
 
    var myDrivers = getDrivers();
    

 

Details Photos Edit more

Details

ID: 5231

NAME: TRY-example-error-checking

DESCRIPTION: #### - tutorial with better code example in comments

START DATE TIME: 2015-06-04 17:16:01

EST DURATION: 01:00:00

END DATE TIME: 2015-06-04 18:16:01

STATUS: To-Do

PRIORITY: -5

OWNER ID: 75

Content Photos Edit more

photos

photos for this task

actions

Agenda Email task SMS task Priorities