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 に答える