为什么我不能提交表格? PHP cURL [英] Why can't I submit form? PHP cURL
问题描述
我想写一个脚本,将获取我的数据用量的一个月,并导航我使用cURL的网址。不幸的是,我不熟悉它。这是我的代码到目前为止:
I am trying to write a script that will get my data usage for the month, and to navigate the url I am using cURL. Unfortunately, I am not familiar with it. This is my code so far:
<?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" ;
?>
由于某种原因,这不起作用。我试过这么多变化,但输出总是相同的。它给我原始页面。有人知道我在做什么错了吗?
For some reason though, this does not work. I've tried so many variations, but the output is always the same. It gives me the original page. Does anyone know what I am doing wrong? I've been banging my head on this for hours.
谢谢!
推荐答案
我不是100%肯定,但是看着url的源,我觉得你应该卷曲窗体的动作,而不是窗体所在的页面。你模拟一个提交,因此您应该尝试将表单内容提交到表单的操作。
I am not 100% sure, but after looking at that source of the url, I feel like you should be curling the action of the form, not the page the form is located in. You are simulating a submit, therefore you should try to submit the forms content to the action of the form.
<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'
) ;
这篇关于为什么我不能提交表格? PHP cURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!