php cURL - 加载具有 CloudFlare 保护的站点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18500088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cURL - Load a site with CloudFlare protection
提问by Marcin
I have a site which I want to load using cURL. However, the site I'm talking about is using cloudflare protection. While on cURL request => it says 'checking your browser, you will be redirected in 5 seconds' and I'm getting redirected to the page that doesn't exists because as I think I didn't pass some protection test.
我有一个要使用 cURL 加载的站点。但是,我正在谈论的站点正在使用 cloudflare 保护。在 cURL 请求 => 上,它说“正在检查您的浏览器,您将在 5 秒内被重定向”并且我被重定向到不存在的页面,因为我认为我没有通过一些保护测试。
I've been looking for my answer for a long and i found only two useful links:
我一直在寻找我的答案,我只找到了两个有用的链接:
But still I can't figure it out. Any help for me?
但我还是想不通。对我有什么帮助吗?
回答by xxdesmus
That would be CloudFlare's I'm Under Attack Mode --> http://blog.cloudflare.com/introducing-im-under-attack-mode
那将是 CloudFlare 的 I'm Under Attack Mode --> http://blog.cloudflare.com/introducing-im-under-attack-mode
If you are the owner of the site you should whitelist your own IP address. If you're a visitor to the site either
如果您是该站点的所有者,则应将您自己的 IP 地址列入白名单。如果您是该网站的访问者
1.) The website owner has the feature enabled on their own website in which case it's intentional and there is no way around that as they are protecting their website or
1.) 网站所有者在他们自己的网站上启用了该功能,在这种情况下,这是故意的,因为他们正在保护他们的网站或
2.) You are loading the site too often -- and you're triggering CloudFlare's DDOS protection.
2.) 您加载站点过于频繁——并且您触发了 CloudFlare 的 DDOS 保护。
p.s. Disclaimer: I work for CloudFlare.
ps 免责声明:我为 CloudFlare 工作。
回答by ticoombs
You can get around the in-under-attack-mode by selecting 'Copy as cUrl' in the network section under developer tools of any major browser.
您可以通过在任何主要浏览器的开发人员工具下的网络部分中选择“复制为 cUrl”来绕过攻击中模式。
This copies all the required cookies so your curl can be 'authenticated'. How long these cookies last i would assume would be up to cloudflare.
这会复制所有必需的 cookie,以便可以“验证”您的 curl。我认为这些 cookie 能持续多久取决于 cloudflare。
SideNote: The curl must be run on the same IP as you were loading the site with. Also for any real test/developing environment I would suggest seleniumand/or phantomjswhich are alot better and easily scriptable languages for website testing.
旁注:curl 必须在与加载站点时使用的 IP 相同的 IP 上运行。同样对于任何真正的测试/开发环境,我建议使用selenium和/或phantomjs,它们是用于网站测试的更好且易于编写脚本的语言。
curl 'https://ilikeurls.net/ourpage.php?do=command' \
-H 'Host: ilikeurls.net' \
-H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
-H 'Accept-Language: en-US,en;q=0.5' \
-H 'Referer: https://ilikeurls.net/outpage.php' \
-H 'Cookie: all required cookies will appear here' \
-H 'Connection: keep-alive'\
--compressed
Though you might be better off using selenium or phantomjs to script out these tests.
尽管您最好使用 selenium 或 phantomjs 来编写这些测试的脚本。