I'm trying to POST a message to a MarkLogic application server with digest security using Node. The equivalent curl request works fine:
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
I tried using the NPM request module, which says it supports digest requests. I was able to do a GET request successfully. Here's one attempt at 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);
}
);
That get's me a 401. The username and password are correct. I also tried like this:
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);
});
That gets me a 302. I feel like I must be missing something straightforward here.
- node v0.10.31
- MarkLogic 8.0-2
followAllRedirectsoption in the first attempt shown above is supposed to handle the redirect, but since that gives a 401, it seems it isn't doing so correctly. - Dave Cassel{ sendImmediately: false }in theauthobject is supposed to handle the initial 401 in a digest negotiation; I'm not sure what's going wrong here. I've usedrequestwith ML7 extensively here: github.com/joemfb/mlpm-registry/blob/master/server.js; notecreateOrUpdateUser()andsaveRenderedMarkdown()(and, yes, that code is a mess ;)). - joemfb