Good afternoon.
There is a website written in asp code which I don't have access to. Programmer support online promises to write an external service to send the data. But it lasts for a long time, and the data for conducting the analytical work needed now.
The problem is that there first needs to enter a username and password. And the data I want to collect an automatic.
The authentication in the course of the underlying is used because I don't see that the browser in the headers kept this info after a successful call. And attempts to drop all my failed. So I decided to use the module request. And to send the first post for authorization and then saved the cookie to use for get requests. And here the problems started.
For authentication, use the page to login which then is sent Form Data with username and password.
Through various eksperimentov begat this code:
var postData={
Login: 'login', PWD: 'pasword'
};
require('request').post({
uri:"<a href="http://mysite/Login.asp">http://mysite/Login.asp</a>",
headers:{'content-type': 'application/x-www-form-urlencoded'},
body:require('querystring').stringify(postData)
},function(err,res,body){
console.log(body);
});
<title>Object moved</title>
<h1>Object Moved</h1>This object may be found <a href="/Main.asp">here</a>.
1. Activate cookies: var request = request.defaults({jar: true})
2. Also, try to add parameter: followAllRedirects: true
3. Why you can not continue in the callback from the post add request.get('http://mysite/Main.asp', function(err,res,body){ console.log(body); });
Find more questions by tags Node.js