1

我正在尝试使用适用于 NodeJs 的 Unirest HTTP 库持久登录到站点,但是在发布登录凭据后,我只能获得登录页面作为回报(例如,不成功)。

登录表单:

<form method="post" action="/user/account/login/">
<div id=loginform>
<label class="field-title">Username </label><label class="txt-field"><input name="username" type="text" tabindex="1" /></label>
<label class="field-title">Password </label><label class="txt-field"><input name="password" type="password" tabindex="2"/></label>
</div>

我试过这个:

var unirest = require('unirest');
var loginUrl = "https://example.org/user/account/login/";
var username = 'myuser';
    password = 'mypass';

var Request = unirest.post(loginUrl);

Request.auth({
  user: username,
  pass: password,
  sendImmediately: true
});

Request.end(function (response) {
  console.log(response.body);
});

和这个:

Request.auth({
  username: username,
  password: password,
  sendImmediately: true
});

.. 和这个:

Request.send({
    username: username,
    password: password
});

但无济于事。我不必使用 Unirest,是否有其他简单的库可用于登录并使用登录 cookie 进行进一步请求?

4

0 回答 0