卷曲访问需要从不同的页面的登录页面 [英] CURL to access a page that requires a login from a different page

查看:173
本文介绍了卷曲访问需要从不同的页面的登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2页: xyz.com/a xyz.com/b 。我只能访问 xyz.com/b 当且仅当我登录到 xyz.com/a 第一。如果访问 xyz.com/b 无需通过其他的打算,我只是得到通过浏览器拒绝访问(无重定向登录)。有一次,我在登录 xyz.com/a ,我可以访问其他。

I have 2 pages: xyz.com/a and xyz.com/b. I can only access xyz.com/b if and only if I login to xyz.com/a first. If accessing xyz.com/b without going through the other, I simply get access denied (no redirect to login) via the browser. Once I login at xyz.com/a, I can access the other.

我的问题是使用curl命令这样做。我可以使用curl成功登录到 xyz.com/a ,但随后尝试 xyx.com/b 和我得到访问被拒绝。

My problem is doing this using the curl command. I can login successfully to xyz.com/a using curl, but then try xyx.com/b and I get access denied.

我用下面的:

curl --user user:pass https://xyz.com/a  #works ok
curl https://xyz.com/b #doesn't work

我已经用第二行以&放审判;未经用户/密码的一部分,仍然无法正常工作。这两个网页使用相同的CA,所以这不是一个问题。有什么建议么?谢谢

I've tried using the second line with & without the user/password part and still doesn't work. Both pages uses the same CA, so that's not a problem. Any suggestions? Thanks

推荐答案

该网站可能使用饼干来存储您的会话信息。当您运行

The web site likely uses cookies to store your session information. When you run

curl --user user:pass https://xyz.com/a  #works ok
curl https://xyz.com/b #doesn't work

卷曲运行两次,在两个单独的会话。因此,第二个命令运行时,由第一个命令设置Cookie不可用;它就像您登录到页面 A在一个浏览器会话,并试图在不同的访问页面 B 之一。

curl is run twice, in two separate sessions. Thus when the second command runs, the cookies set by the 1st command are not available; it's just as if you logged in to page a in one browser session, and tried to access page b in a different one.

您需要做的是什么的保存的第一个命令创建的cookie:

What you need to do is save the cookies created by the first command:

curl --user user:pass --cookie-jar ./somefile https://xyz.com/a

,然后读回连续第二时:

and then read them back in when running the second:

curl --cookie ./somefile https://xyz.com/b

另外,您可以尝试下载在同一个命令这两个文件,​​我认为将使用相同​​的cookie。

Alternatively you can try downloading both files in the same command, which I think will use the same cookies.

这篇关于卷曲访问需要从不同的页面的登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆