gpt4 book ai didi

php - curl 重定向,不起作用?

转载 作者:可可西里 更新时间:2023-11-01 13:06:15 32 4
gpt4 key购买 nike

我正在使用以下代码:

$agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0';

$ch = curl_init();

curl_setopt($ch, CURLOPT_USERAGENT, $agent);

curl_setopt($ch, CURLOPT_URL, "www.example.com");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HEADER, 0);

$output = curl_exec($ch);

echo $output;

但是它重定向到这样:

http://localhost/aide.do?sht=_aide_cookies_

而不是到 URL 页面。

谁能帮我解决我的问题?

最佳答案

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

http://docs.php.net/function.curl-setopt说:

CURLOPT_FOLLOWLOCATION
TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set).

关于php - curl 重定向,不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2565787/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com