2

I have made a http client using Node that sends a post request. However the service has NTLM authentication enabled. How do I add my username and password in the post request ?

var http=require('http')
var options = {
    host: 'kmserver28',
    port: 3535,
    path: '/Alto/Post/PostFetchWS.asmx/FetchPosts',
    method: 'POST'
};

var req = http.request(options, function(res){
    console.log('status: ' + res.statusCode);
    console.log('headers: ' + JSON.stringify(res.headers));
    res.setEncoding('utf8');
    res.on('data', function(chunk){
        console.log("body: " + chunk);
    });
});

req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
});

// write data to request body
req.write('data\n');
req.write('data\n');
req.end();

1 Answer 1

1

Came across this while trying to get basic authorization working. I was able to get it working by adding an authorization header in the options object. Mine was for basic, but NTLM should be similar, I believe:

var api_options = {
host: process.env.API_HOST,
path: process.env.API_PATH,
method: 'POST',
headers: {
    'Content-Type': 'application/json',
    'Content-Length': Buffer.byteLength(body),
    'Authorization': 'Basic ' + new Buffer(process.env.API_USERNAME + ':' + process.env.API_PASSWORD).toString('base64')
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.