0

我正在尝试编写一个脚本来获取我当月的数据使用情况,并导航我正在使用 cURL 的 url。不幸的是,我不熟悉它。到目前为止,这是我的代码:

<?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" ;

?>

但由于某种原因,这不起作用。我尝试了很多变化,但输出总是相同的。它给了我原始页面。有谁知道我做错了什么?几个小时以来,我一直在努力解决这个问题。

谢谢!

4

1 回答 1

2

我不是 100% 确定,但是在查看了 url 的来源之后,我觉得你应该卷曲表单的动作,而不是表单所在的页面。你正在模拟提交,因此你应该尝试将表单内容提交给表单的操作。

<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">&nbsp;</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'
) ;
于 2012-08-06T20:25:07.633 回答