将特定的cURL命令转换为Php cURL

时间:2016-01-20 15:09:57

标签: php curl


我遇到了这个cURL命令的问题。我想通过Php发送请求。 这是我的cURL命令:

curl -i -s -k  -X 'POST' \
-H 'Origin: http://117.239.83.200:2020' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Linux; Android 5.1.1; A0001 Build/LMY48B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Referer: http://117.239.83.200:2020/frmUniversityResult.aspx' \
--data-binary $'__LASTFOCUS=&__EVENTTARGET=ddlSem&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwULLTIxMTE5MjUyMzYPFgIeDFByZXZpb3VzUGFnZQUzaHR0cDovLzExNy4yMzkuODMuMjAwOjIwMjAvZnJtVW5pdmVyc2l0eVJlc3VsdC5hc3B4FgICAw9kFgICAQ9kFgRmD2QWDAIFDxAPFgYeDURhdGFUZXh0RmllbGQFBUFsaWFzHg5EYXRhVmFsdWVGaWVsZAULSW5zdGl0dXRlSUQeC18hRGF0YUJvdW5kZ2QQFQkJU2VsZWN0Li4uBUNTUElUBkNNUElDQQRSUENQBElJSU0GUERQSUFTBEFSSVAETVRJTgRDSVBTFQkBMAExATIBMwE0ATUBNgIxNgIxORQrAwlnZ2dnZ2dnZ2cWAQIBZAIHDxAPFgYfAQUKRGVncmVlQ29kZR8CBQhEZWdyZWVJRB8DZ2QQFRcJU2VsZWN0Li4uCUJURUNIKENFKQlCVEVDSChDTCkJQlRFQ0goRUMpCUJURUNIKEVFKQlCVEVDSChJVCkJQlRFQ0goTUUpBERSQ0UERFJDTAREUkVDBERSRUUFRFJMU0MERFJNRQVEUk1USApNVEVDSChBTVQpCU1URUNIKENFKQlNVEVDSChDTCkJTVRFQ0goRUMpCU1URUNIKEVFKQpNVEVDSChFVkQpCU1URUNIKElUKQlNVEVDSChNRSkDTVRNFRcBMAIzOQI0MQI0MAIzNwIzOAIzNgI4MgI5MAI3MAI3MgI4MwI3MQI3NQMxMDYCNjUDMTA1AjYxAjg3AzExNgI5NQI2MAMxMTAUKwMXZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2cWAQIBZAIJDxAPFgYfAQUDU2VtHwIFA1NlbR8DZ2QQFQkJU2VsZWN0Li4uATEBMgEzATQBNQE2ATcBOBUJATABMQEyATMBNAE1ATYBNwE4FCsDCWdnZ2dnZ2dnZxYBZmQCCw8QDxYGHwEFDUV4YW1Nb250aFllYXIfAgUOU2NoZWR1bGVFeGFtSUQfA2dkEBUFCVNlbGVjdC4uLghNQVkgMjAxNQ1ERUNFTUJFUiAyMDE0CE1BWSAyMDE0DU5PVkVNQkVSIDIwMTMVBQEwBDIyMDAEMjA1MgQyMDA2BDE4NDEUKwMFZ2dnZ2dkZAIPDw9kFgIeB29uY2xpY2sFUCB0aGlzLnZhbHVlPSJQcm9jZXNzaW5nLi4iIDt0aGlzLmRpc2FibGVkID0gdHJ1ZTsgX19kb1Bvc3RCYWNrKCdidG5TZWFyY2gnLCcnKSA7ZAIRDw8WAh4EVGV4dGVkZAIBD2QWAgIBD2QWAgITDzwrAA0AZBgCBQhtdlJlc3VsdA8PZGZkBRF1Y2xHcmQxJGdyZFJlc3VsdA9nZFkzbjDOCTYtz8GQYcnnUncb54ui&__VIEWSTATEGENERATOR=F859A3E9&ddlInst=1&ddlDegree=39&ddlSem=1&ddlScheduleExam=0&txtEnrNo=' \
'http://117.239.83.200:2020/frmUniversityResult.aspx''

而且,这是我在Php中的方法。

<?php
$url = "http://117.239.83.200:2020/frmUniversityResult.aspx?ddlInst=1&ddlDegree=39&ddlSem=1&ddlScheduleExam=0&txtEnrNo=";

$postfields  = array('__EVENTTARGET' => 'btnSearch',
                     '__VIEWSTATEGENERATOR' => 'F859A3E9',
                     'ddlInst'       => '1',
                     'ddlDegree'     => '39',
                     'ddlSem'        => '3',
                     'ddlScheduleExam'  => '2380',
                     'txtEnrNo'         => '14ce055'
                    );
$postdata = http_build_query($postfields);
//var_dump($postdata);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
print_r($result);

curl_close($ch);

?>

但不幸的是,它将我重定向到其索引页面。有人可以帮我解决这个问题吗?

0 个答案:

没有答案