0

我正在尝试使用节点模块请求在网站上进行身份验证,按照说明进行操作后,我似乎仍然无法弄清楚...

使用 Coffeescript 我做了以下事情:

Request {
    url: "https://#{encodeURIComponent(config.email)}:#{encodeURIComponent(config.password)}@#{config.loginURL}"
}, (error, response, body) ->
    if error
        console.log error
    else
        console.log body

这些config值分别是电子邮件、密码和 URL。网址是app.shopify.com/services/partners/auth/login。另外,因为用户名是电子邮件地址,所以我认为最好encodeURIComponent使用登录值。

当我运行它时,我没有收到错误,但输出body只是登录页面的标记。

我也试过这样做:

Request.get config.loginURL, {
    auth: {
        username: config.email
        password: config.password
        sendImmediately: false
    }
}, (error, response, body) ->
    if error
        console.log error
    else
        console.log body

在这种情况下,因为凭据不是 URL 的一部分,所以我没有encodeURIComponent'd 他们。此外,登录 URL 已https://添加到它前面。

谁能指导我正确的方向?

4

1 回答 1

0

如果页面没有使用基本/摘要身份验证,而是使用基于表单的身份验证,则需要 POST 表单值:

request(config.loginURL, {
  method: 'POST',
  form: {
    // these key names come from the `name` field in the login form's HTML
    login: config.email,
    password: config.password
  }
}, function(err, res, body) {
  // ...
});
于 2014-10-24T22:04:37.323 回答