【发布时间】:2014-12-08 09:31:18
【问题描述】:
我正在请求一个带有自动登录的 cURL 的站点,尽管脚本登录后的每个 GET 请求都可以正常运行,但 URL 中将包含“localhost”而不是站点的实际域,因此它会抛出一个 @ 987654325@未找到错误。
示例:不是https://remotesite.com/dashboard,而是http://localhost.com/dashboard (另请注意,http://localhost.com/dashboard 没有使用 https)
这是我的代码:
$curl = curl_init();
$user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
$url = 'https://remotesite.com/dashboard';
$post_data = 'username=username&password=password&cookie=true&destination=&login=Log+In';
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt ($curl, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt ($curl, CURLOPT_COOKIEJAR, "cookie.txt");
$result = curl_exec ($curl);
$errmsg = curl_error($curl);
echo $result;
【问题讨论】:
-
如果是post请求,你应该将
CURLOPT_POST设置为TRUE。根据您的 PHP 版本,默认情况下它可能是FALSE。看看有没有效果。 -
@Max 试过但没用 :(
-
你在代理后面吗?
-
@Max 不知道,我在工作中使用网络。
-
您使用的是 Linux 还是 Windows?可能是因为您使用的是办公室互联网连接
标签: php curl https http-status-code-404