我使用Node发送了一个发送帖子请求的http客户端。但是,该服务已启用NTLM身份验证。如何在帖子请求中添加我的用户名和密码?
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();
答案 0 :(得分:0)
在尝试获得基本授权的同时遇到了这个问题。我能够通过在options对象中添加授权头来使其工作。我是基本的,但NTLM应该是相似的,我相信:
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')
}