0
我有一些代碼通過捲曲登錄到一個網站:遷移捲曲請求wget的請求登錄到網站不能正常工作
$url = "https://www.site.net/post/login.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, "Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D167 Safari/9537.53");
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);
我需要能夠改變用戶代理上的蒼蠅,和我根據我的瞭解,不能真的這樣做。所以我決定遷移到WGET:
shell_exec("wget -qO- --max-redirect=1 --save-cookies=\"cookie.txt\" --referer=\"https://www.site.net/Index.page\" --user-agent=\"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D167 Safari/9537.53\" --post-data=\"screenName=$username&kclq=$password&submitEvent=1&TCNK=authenticationEntryComponent&enterClicked=true&ajaxSupported=yes\" https://www.site.net/post/login.page");
但是,這甚至沒有將cookie保存到文件中。我在做什麼錯了/我應該修改什麼?
所有你需要做的是改變用戶代理選項字符串......爲什麼開關什麼時候你已經有了代碼? – Brad
它似乎沒有工作。基本上我使用cURL登錄,然後通過WGET獲取頁面。但是,傳遞'--user-agent'似乎並不會切換用戶代理。 – Someone
請勿使用wget。你有cURL ...你爲什麼要用cURL和wget? – Brad