CURL模拟POST传递参数问题
程序员文章站
2022-05-01 13:57:36
...
请大家帮我看一下,我使用CURL函数模拟页面间传递参数,但是测试后发现参数总是不能传递到指定的页面,请帮我分析一下,我的代码附上:
header("Content-Type: text/html; charset=utf-8");
include("basic-lanconf.php");
echo"--------------------basic-lan配置结果-------------------";
echo"-------------------------------------------------------";
echo"(1).basic-lan配置测试结果:";
$url="http://192.168.0.1/tomato.cgi";
$head=array();
$head[]="Authorization: Basic " . base64_encode($admin.":".$pass);
$curlPost="lan_ipaddr=$lan_ipaddr&lan_netmask=$lan_netmask&f_dhcpd_enable=$f_dhcpd_enable" .
"&dhcpd_startip=$dhcpd_startip&dchpd_endip=$dchpd_endip&dhcp_lease=$dhcp_lease";
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);//要求结果保存到字符串中还是输出到屏幕上,参数为1,不返回到屏幕
curl_setopt($ch,CURLOPT_HTTPHRADER,$head);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);
$data=curl_exec($ch);
curl_close($ch);
echo "data=$data";
echo "lan-ipaddr=$lan_ipaddr";
echo "lan-netmask=$lan_netmask";
echo "f_dchpd_enable=$f_dhcpd_enable";
echo "dhcpd_startip=$dhcpd_startip";
echo "dhcpd_endip=$dhcpd_endip";
echo "dhcp_lease=$dhcp_lease";
?>
header("Content-Type: text/html; charset=utf-8");
include("basic-lanconf.php");
echo"--------------------basic-lan配置结果-------------------";
echo"-------------------------------------------------------";
echo"(1).basic-lan配置测试结果:";
$url="http://192.168.0.1/tomato.cgi";
$head=array();
$head[]="Authorization: Basic " . base64_encode($admin.":".$pass);
$curlPost="lan_ipaddr=$lan_ipaddr&lan_netmask=$lan_netmask&f_dhcpd_enable=$f_dhcpd_enable" .
"&dhcpd_startip=$dhcpd_startip&dchpd_endip=$dchpd_endip&dhcp_lease=$dhcp_lease";
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);//要求结果保存到字符串中还是输出到屏幕上,参数为1,不返回到屏幕
curl_setopt($ch,CURLOPT_HTTPHRADER,$head);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$curlPost);
$data=curl_exec($ch);
curl_close($ch);
echo "data=$data";
echo "lan-ipaddr=$lan_ipaddr";
echo "lan-netmask=$lan_netmask";
echo "f_dchpd_enable=$f_dhcpd_enable";
echo "dhcpd_startip=$dhcpd_startip";
echo "dhcpd_endip=$dhcpd_endip";
echo "dhcp_lease=$dhcp_lease";
?>
回复讨论(解决方案)
$url="http://192.168.0.1/tomato.cgi"; ?
你知道他需要接受什么样的数据吗?
先换成 php 程序进行测试
$url="http://192.168.0.1/tomato.cgi"; ?
你知道他需要接受什么样的数据吗?
先换成 php 程序进行测试
他那是用番茄刷的路由器wrt,估计挺难换php测试了,呵呵
上一篇: Python如何使用cx_Oracle调用Oracle存储过程的示例
下一篇: 实现一个计算器的实例
推荐阅读
-
PHP函数分享之curl方式取得数据、模拟登陆、POST数据
-
js对象转json对象(post请求传递json参数)
-
Python3模拟curl发送post请求操作示例
-
php curl post 时出现的问题解决
-
JSP中js传递和解析URL参数以及中文转码和解码问题
-
通过curl模拟post和get方式提交的表单类
-
解决SpringMVC Controller 接收页面传递的中文参数出现乱码的问题
-
php curl模拟post提交数据示例
-
Linux下模拟http的get/post请求(curl or wget)详解
-
Angularjs中$http以post请求通过消息体传递参数的实现方法