我正在使用Cookie处理php cURL以提交jQuery / Java表单并接收结果。
我想要这个脚本:
到目前为止,我的脚本在下面,我能够:
1)访问URL并保存要提交的Cookie。
<?php
$get_cookie_page = 'https://unlock.telstra.com/iphoneunlock/main';
echo curl_download($get_cookie_page);
function curl_download($Url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
$http_headers = array(
'Host: unlock.telstra.com',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2',
'Accept: /*',
'Accept-Language: en-us,en;q=0.5',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Connection: keep-alive'
);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
?>
2)使用Cookie并获取FORM
<?php
$imei = '013064001494963';
$submit = 'Submit';
$fields = array(
"imei" => $imei,
"_eventId_submit" => $submit
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://unlock.telstra.com/iphoneunlock/main?execution=e1s1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
$http_headers = array(
'Host: unlock.telstra.com',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2',
'Accept: /*',
'Accept-Language: en-us,en;q=0.5',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Connection: keep-alive'
);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
var_dump($info);
var_dump($output);
curl_close($ch);
?>
正如您在上面的代码中看到的,我添加了 CURLOPT_POSTFIELDS 但是在结果上我得到的FORM为空。
有关如何在此表单中粘贴值并获得结果的任何建议吗?
这是表格:
<form id="unlockForm" class="form wide" action="/iphoneunlock/main?execution=e1s1" method="post">
<input type="text" pattern="\d*" name="imei" id="imei-details" maxlength="15"/>
<input type="submit" id="submit" tabindex="4" name="_eventId_submit" class="btn" value="Submit"/>
<input type="submit" id="cancel" tabindex="4" name="cancel" class="btn" value="Cancel"/>
</form>
有什么建议吗?谢谢你的帮助。