为什么通过 PHP cURL GET 出现 404 错误,但在浏览器中运行正常?
StumbleUpon 最近更改了他们的框架,他们的 API 不再工作,所以我正在尝试编写一个 PHP 脚本来访问我的 Stumble 历史记录。
令人尴尬的是,我陷入了尝试获取登录页面的简单步骤;)
https://www .stumbleupon.com/login/ 在我的浏览器中加载正常
但是这个 PHP 代码显示了 404 页面:
// Vars
$url = "https://www.stumbleupon.com/login/";
$user_agent = "Mozilla/5.0";
// Curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$response = curl_exec($ch);
echo $response;
我想它们可能会阻止某些用户代理,所以我尝试了我的浏览器正在使用的相同的代理,但是没有运气。我还尝试从不同的 IP 运行脚本来消除 IP 禁止问题。我对这个真的一无所知……非常奇怪。
有什么想法吗?
StumbleUpon recently changed their framework and their API no longer works, so I'm trying to write a PHP script to access my Stumble history.
Embarrassingly enough, I'm stuck at the simple step of trying to GET the login page ;)
https://www.stumbleupon.com/login/ loads fine in my browser
But this PHP code displays a 404 page:
// Vars
$url = "https://www.stumbleupon.com/login/";
$user_agent = "Mozilla/5.0";
// Curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$response = curl_exec($ch);
echo $response;
I've thought maybe they block certain user agents, so I've tried the same one my browser is using, but no luck. I've also tried running the script from different IPs to eliminate an IP ban issue. I'm really clueless on this one...very odd.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 https://www.stumbleupon.com/login.php 代替。你输入的 URL 会返回 404 给我。
Try using https://www.stumbleupon.com/login.php instead. The URL you put returns a 404 for me to.
他们可能正在寻找其他一些 HTTP 标头。您应该尝试查看浏览器在使用
live http headers
之类的内容请求此页面时会执行什么操作,并尝试一次将一个 HTTP 标头合并到您的脚本中,看看哪一个可以解决您的问题。They could be looking for some other HTTP header. You should try seeing what your browser does when it requests this page with something like
live http headers
and try to incorporate one HTTP header at a time into your script and see which one solves your issue.