因此,我使用cURL在此處登錄到網站並欺騙用戶代理。我有兩個常量:一個叫做IOS
,它是一個iOS用戶代理,另一個叫做CHROME
,它是一個Chrome用戶代理。下面是登錄代碼:使用cURL在多個請求中多次切換用戶代理
public function signIn($username, $password)
{
$url = "https://www.site.net/post/Index.page";
$cookie = "cookie.txt";
$postdata = "screenName=$username&kclq=$password&submitEvent=1&TCNK=authenticationEntryComponent&enterClicked=true&ajaxSupported=yes";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, IOS);
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_REFERER, "https://www.site.net/Index.page");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
curl_close($ch);
}
在隨後的請求,我想用戶代理更改從IOS
到CHROME
,它似乎並不工作(我更改爲CHROME
和網站仍然提供打開手機頁面)。當我運行這個請求:
curl -L -X POST -b "cookie.txt" --user-agent " . CHROME . " https://site.net
它不會成爲一個桌面網站,但移動一個。登錄時是否可以更改用戶代理?