小编erd*_*pak的帖子

HTTP错误411,请求必须分块或具有内容长度

我正在尝试登录到远程网站,但在下面的代码"HTTP错误411,请求必须分块或具有内容长度"时收到错误.

$username = "psker";
$password = "Admin123";
$url="https://192.18.11.33/Login.aspx?FromMasterLogin=true"; 
$postinfo = 'txtUserName='.$username.'&txtpassword='.$password.'&txtUserName_ClientState={"enabled":true,"emptyMessage":""}&txtpassword_ClientState={"enabled":true,"emptyMessage":""}&btnLogin_ClientState&btnClearSession_ClientState&rdwindowForget_ClientState&rdwindowEnforce_ClientState&rdWindowPublicNewsAlerts_ClientState&RadWindowManager1_ClientState';
$cookie_file_path = "/cookies.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$headers = array( 
            "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
            "Accept-Encoding:gzip, deflate, br",
            "Accept-Language:en-US,en;q=0.8",
            "Cache-Control:max-age=0",
            "Connection:keep-alive",
            "Content-Length:1025",
            "Content-Type:application/x-www-form-urlencoded"
        );
curl_setopt($ch, CURLOPT_HTTPHEADER,  $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, "https://192.18.11.33/RGCS/Default.aspx?dd=0");
$html = curl_exec($ch);
echo $html;
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)

以下是登录页面的原始标题:

Request URL:https://192.18.11.33/Login.aspx?FromMasterLogin=true
Request Method:POST
Status Code:302 …
Run Code Online (Sandbox Code Playgroud)

php curl

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

curl ×1

php ×1