[英]Why can't I submit form? PHP cURL
我正在嘗試編寫一個腳本來獲取本月的數據使用情況,並導航我使用cURL的網址。 不幸的是,我不熟悉它。 到目前為止這是我的代碼:
<?php
$url = 'https://apps.nwtel.ca/cable_usage/login.jsp' ;
$id = "------------" ;
$ch = curl_init() ;
curl_setopt( $ch, CURLOPT_URL, "$url" ) ;
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ) ;
curl_setopt( $ch, CURLOPT_POST, true ) ;
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ) ;
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ) ;
$data = array(
'MAC' => "$id",
'submit_btn' => 'submit'
) ;
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data ) ;
$output = curl_exec( $ch ) ;
curl_close( $ch ) ;
echo "$output\n" ;
?>
但出於某種原因,這不起作用。 我嘗試了很多變化,但輸出總是一樣的。 它給了我原始頁面。 有誰知道我做錯了什么? 幾個小時以來,我一直在喋喋不休。
謝謝!
我不是百分百肯定,但在查看網址的來源后,我覺得你應該卷曲表單的動作,而不是表單所在的頁面。你正在模擬提交,因此你應該嘗試將表單內容提交給表單的操作。
<form method="post" action="j_security_check" id="usage_login">
<input type="hidden" name="j_target_url" value="secured/index.jsp" />
<div class="form_input">
<label for="MAC">HFC or CM MAC Address:</label>
<input type="Text" name="MAC" id="MAC" onKeyPress="onKeyPress(this.form)" />
<a href="#mac_num_help" title="Your HFC or CM MAC Address is located on the sticker on the bottom of your modem" class="help">MAC Address Help</a>
<input type="hidden" name="j_username" id="j_username" />
</div>
<div class="form_input">
<input type="hidden" name="j_password" id="j_password" maxlength="6" size="7" value="123456" />
</div>
<div class="form_input">
<label for="submit_btn"> </label>
<input type="submit" name="submit_btn" id="submit_btn" value="Submit" onclick="fixAndSubmit(this.form)" />
</div>
</form>
嘗試改變:
$url = 'https://apps.nwtel.ca/cable_usage/login.jsp' ;
至
$url = 'https://apps.nwtel.ca/cable_usage/j_security_check' ;
也改變了
$data = array(
'MAC' => "$id",
'submit_btn' => 'submit'
) ;
至
$data = array(
'MAC' => "$id",
'submit_btn' => 'submit',
'j_password' => '123456',
'j_username' => '3D3D3D3D3D3D' //should be your MAC address all capitalize without using special characters
'j_target_url' => 'secured/index.jsp'
) ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.