PHP cURL不发布数据

时间:2017-01-16 00:45:46

标签: php curl

最近我一直在做一个小项目,以便将一些信息发布到登录页面,这样我就可以轻松访问学校的日程安排了。无论如何,问题是我无法将密码发布到网站或提交凭据。实际上唯一有效的是发布用户名。这是代码:

<?php
    $ch = curl_init();

    $datafield = '__VIEWSTATE=%2FwEPDwULLTE2OTMyMjE5NzBkZKC3UMzpz2mvo4EH%2FkIAaElJ4cqX&__EVENTVALIDATION=%2FwEdAASUve01SuLnSrJ144bDmbDAY3plgk0YBAefRz3MyBlTcHY2%2BMc6SrnAqio3oCKbxYainihG6d%2FXh3PZm3b5AoMQa2TJXV1d0bJySVXtESf1LAcmqGM%3D&txtUserName=12345678&txtPassword=Password12345&btnLogin=Login';

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_URL, 'https://studentportal.eschooldata.com/Login.aspx?ReturnUrl=%2fhhs');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $datafield);

    curl_setopt($ch, CURLOPT_URL, 'https://studentportal.eschooldata.com/Login.aspx?ReturnUrl=%2fSchedulePrint.aspx');
    $result = curl_exec($ch);

    curl_close($ch);
    echo $result;
?>

我查看了许多帖子,但我仍然不明白这个问题。任何帮助,将不胜感激。当然,这些并不是真正的凭据。

修改 所以我将代码更改为此,我删除了重复的CURLOPT_URL,但现在甚至没有输入用户名。没有任何事情发生,页面只显示没有任何结果。

<?php
    $ch = curl_init();

    $username = '12345678';
    $password = 'Password12345';

    $datafield = array('txtUserName' => $username, 'txtPassword' => $password);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_URL, 'https://studentportal.eschooldata.com/Login.aspx?ReturnUrl=%2fhhs');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($datafield));
    curl_exec($ch);

    $result = curl_exec($ch);

    curl_close($ch);
    echo $result;
}

&GT;

0 个答案:

没有答案