Link to home
Start Free TrialLog in
Avatar of ank5
ank5Flag for India

asked on

Pass custom headers using request module

I am using npm request module (https://www.npmjs.com/package/request) to post binary content to a servlet. The binary content is received as part of http request, using the npm request module it is then posted to the J2ee server.

Along with the post, I need to pass some custom headers. I am using the below code to do that

var req = require('request');
function upload(request, response) {
    var options = {
      headers: {
        'customheader1': 'val1',
        'customheader2': 'val2'
      }
    };

    var target = req.post('http://'+host+':'+port+'/myapp/Upload', options);
    request.pipe(target);

    target.on('finish', function() {
        console.log('Uploaded with headers');
    })
}

Open in new window


However, the headers are going as blank to the server. What would be the right way to pass headers using request.post?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial