这是输出。没有提到 cookie
请求标头缺少 Cookie:
Host: www.emuparadise.me
Accept: */*
Accept-Encoding: deflate, gzip
Referer: https://m.emuparadise.me/
将 $request 更改为:
$cookie = '[downloadcaptcha=1'
$request = array();
$request[] = "Host: www.emuparadise.me";
$request[] = "Accept: */*";
$request[] = "Accept-Encoding: deflate, gzip";
$request[] = "Referer: https://m.emuparadise.me/";
$request[] = "Cookie: $cookie";
我已经尝试过了,但网站仍然要求验证码。
看一下我贴的 JS 代码。它取自网站的
禁用验证码的功能
如果我有一个 URL 可以测试,我可以更好地帮助你。
如果有重定向,您必须使用curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
您可能必须使 HTTP 请求标头看起来与 JS HTTP 标头相同。
您需要查看 cURL HTTP 请求和响应,并将其与 JS HTTP 请求和响应进行比较。
查看 JS HTTP 请求和响应:
- 右击页面
- 选择 Inspect (Chrome) 或 Insect Element (FireFox)
- 选择“网络”标签
- 转到带有 JS 请求的页面,或者如果已经存在,请刷新。
PHP代码疑难解答:
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request);
curl_setopt($ch, CURLOPT_ENCODING,"");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_FAILONERROR,true);
curl_setopt($ch, CURLOPT_ENCODING,"");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$data = curl_exec($ch);
if (curl_errno($ch)){
$data .= 'Retreive Base Page Error: ' . curl_error($ch);
}
else {
$info = rawurldecode(var_export(curl_getinfo($ch),true));
$skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE));
$responseHeader= substr($data,0,$skip);
$response = substr($data,$skip);
var_export($info);
echo "----------------------------------\n$responseHeader\n--------------------------\n$response \n------------------------------------\n";
}
原帖
curl_setopt($ch, CURLOPT_COOKIE, $cookie );
单个 Cookie
$cookie = 'CookieName=CookieValue'
多个 Cookie 以分号分隔。最后一个 cookie 后没有分号。
$cookie = 'CookieName=CookieValue; CookieName=CookieValue'
curl_setopt($ch, CURLOPT_COOKIE, $cookie );
也可以使用CURLOPT_HTTPHEADER设置Cookie
请参阅以下示例的最后一行。
curl_setopt($ch, CURLOPT_HTTPHEADER, $request);
$request = array();
$request[] = "Host: www.example.com";
$request[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$request[] = "User-Agent: MOT-V9mm/00.62 UP.Browser/6.2.3.4.c.1.123 (GUI) MMP/2.0";
$request[] = "Accept-Language: en-US,en;q=0.5";
$request[] = "Connection: keep-alive";
$request[] = "Cache-Control: no-cache";
$request[] = "Pragma: no-cache";
$request[] = "Cookie: $cookie";