Php 正在将cURL请求迁移到WGET请求以登录网站不工作

Php 正在将cURL请求迁移到WGET请求以登录网站不工作,php,curl,wget,Php,Curl,Wget,我有一些代码可以通过cURL登录到网站: $url = "https://www.site.net/post/login.page"; $cookie = "cookie.txt"; $postdata = "screenName=$username&kclq=$password&submitEvent=1&TCNK=authenticationEntryComponent&enterClicked=true&ajaxSupp

我有一些代码可以通过cURL登录到网站:

    $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");

但是,这甚至不是将cookies保存到文件中。我做错了什么/应该修改什么?

您的
wget
版本可能不支持
--max redirect=1
,因此请从命令中删除该参数,然后重试。它应该对你有用

或者,curl命令行:

curl -L -X POST --cookie-jar "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" --data "screenName=$username&kclq=$password&submitEvent=1&TCNK=authenticationEntryComponent&enterClicked=true&ajaxSupported=yes" http://localhost/post.php
另一个选项,通过以下方式从php脚本更改代理:

http://yourdomain/code.php?agent=Opera 9.0
在php脚本顶部添加以下行:

$agent = "Mozilla 6.0";
if(isset($_GET['agent'])){
    $agent = $_GET['agent'];
}
并将此行的curl代码
CURLOPT_USERAGENT
更改为以下代码:

curl_setopt($ch, CURLOPT_USERAGENT, $agent);
现在,通过以下方式从浏览器浏览php脚本:

http://yourdomain/code.php?agent=Opera 9.0

您只需更改user agent选项的字符串。。。既然你已经有了代码,为什么还要切换所有东西呢?它似乎不起作用。基本上,我使用cURL登录,然后通过WGET获取页面。但是,传递
--user agent
似乎不会切换用户代理。请不要使用wget。你有卷发。。。你为什么要用卷发和wget?哦,是的……我为什么要这样做?@有人,呵呵,真有趣。