Answer the question
In order to leave comments, you need to log in
How to make node.js authenticate on a third party resource?
Good afternoon.
There is a site written in asp to the code of which I do not have access. The programmer who maintains the resource promises to write an external service to send data. But this has been going on for a long time, and the data for conducting your analytical activities is needed now.
The problem is that there you must first enter a username and password. And I want to collect data automatically.
Authentication along the way is not basic, because I don’t see the browser storing this information in the headers after a successful login. And yes, all my attempts to do so have failed. That's why I decided to use the request module . And first send a post for authorization and then use the saved cookies for get requests. And here the problems began.
The page is used for authentication.login with which Form Data is then sent with a login and password.
Through various experiments I came up with the following code:
var postData={
Login: 'login', PWD: 'pasword'
};
require('request').post({
uri:"http://mysite/Login.asp",
headers:{'content-type': 'application/x-www-form-urlencoded'},
body:require('querystring').stringify(postData)
},function(err,res,body){
console.log(body);
});
<head><title>Object moved</title></head>
<body>
<h1>Object Moved</h1>This object may be found <a HREF="/Main.asp">here</a>.</body>
Answer the question
In order to leave comments, you need to log in
1. Enable cookies: var request = request.defaults({jar: true})
2. Also try adding a parameter: followAllRedirects: true
3. Why can't you add request.get(' http:/ /mysite/Main.asp ', function(err,res,body){ console.log(body); });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question