我尝试使用Node将消息发布到具有摘要安全性的MarkLogic应用服务器。等效的curl请求正常工作:
curl -v -X POST --anyauth -u admin:admin --header "Content-Type:application/json" \
-d '{"user-name":"joe", "password": "cool"}' http://localhost:8002/manage/v2/users
我尝试使用NPM request module,表示它支持摘要请求。我成功地做了一个GET请求。这是POST的一次尝试:
request(
{
'url': 'http://localhost:8000/manage/v2/users',
'method': 'POST',
'auth': {
'user': 'admin',
'password': 'admin',
'sendImmediately': false
},
'followRedirect': true,
'followAllRedirects': true,
'json': true,
'body': {'user-name':'joe', 'password': 'cool'}
},
function(error, response, body) {
console.log('callback: ' + response.statusCode);
}
);
这就是我的401.用户名和密码是正确的。我也尝试过这样:
request
.post(
'http://localhost:8000/manage/v2/users',
{'user-name':'joe', 'password': 'cool'})
.auth('admin', 'admin', false)
.on('response', function(response) {
console.log('response: ' + JSON.stringify(response));
})
.on('error', function(error) {
console.log('error: ' + error);
});
这让我变成了302.我觉得我必须在这里找到一些直截了当的东西。
答案 0 :(得分:2)
原来有一个简单的解决方案:curl请求有效,因为我使用localhost:8002;节点请求失败,因为我使用localhost:8000。咄。 302重定向告诉我使用8002而我错过了。
答案 1 :(得分:0)
我很确定我遇到此问题时的解决方案是更改应用服务器中的身份验证设置" digest"到" digestbasic"。 (回答是因为我没有足够的代表在任何地方发表评论。)