php发送http请求

heroblues 2011-01-07 10:18:12
index.php页面

<form method="post" action="test.php">
类型:<input type="text" id="type" name="type"/><br>
电话:<input type="text" id="phnum" name="phnum"/><br>
分机号:<input type="text" id="ext" name="ext"/>
<input type="submit" id="sub" name="sub" value="提交"/>
</form>

test.php页面

$A=trim(urlencode($_REQUEST['type']));
$B=trim(urlencode($_REQUEST['phnum']));
$C=trim(urlencode($_REQUEST['ext']));
$params = "A=$A&B=$B&C=$C";

$length = strlen($params);
$fp = fsockopen("localhost",808,$errno,$errstr,10) or exit($errstr."--->".$errno);
$header = "GET /CRM/test2.php HTTP/1.1\r\n";
$header .= "Host:localhost \r\n";
$header .= "Referer:localhost:808/CRM/test2.php \r\n";
$header .= "Content-Length: ".$length."\r\n";
$header .= "Content-Type: text/html \r\n";
$header .= "Connection: Close\r\n\r\n";
$header .= $params."\r\n";
fwrite($fp,$header);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);

test2.php页面

echo $_GET['A']."<br>".$_GET['B']."<br>".$_GET['C'];

我从index.php提交表单后,test.php能够得到提交的数据;
从test.php向test2.php发送http请求后,test2.php得不到数据。
为什么会是这样?难道这种方法不行?请大侠赐教!!
...全文
843 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
heroblues 2011-01-07
  • 打赏
  • 举报
回复
请高人进来看看,该怎么解决啊?!
heroblues 2011-01-07
  • 打赏
  • 举报
回复
我只要能把参数穿给tets2.php就行
goosman 2011-01-07
  • 打赏
  • 举报
回复
我们项目中现在是基于http://scripts.incutio.com/httpclient/这个工具做http客户端...

你具体情况看不到不好说, 建议打开调试跟踪一下看问题出在哪里才好决定怎么解决
lijpwsw 2011-01-07
  • 打赏
  • 举报
回复
$params是不是要加个

$A=trim(urlencode($_REQUEST['type']));
$B=trim(urlencode($_REQUEST['phnum']));
$C=trim(urlencode($_REQUEST['ext']));
$params = "?" . "A=$A&B=$B&C=$C";


heroblues 2011-01-07
  • 打赏
  • 举报
回复
test.php向test2.php发送请求时是用get方式发送的,和index.php没关系吧?
lijpwsw 2011-01-07
  • 打赏
  • 举报
回复
post提交表单要用$_POST,$_REQUEST[]都可以用,$_GET只能用于get方式提交的表单……
life169 2011-01-07
  • 打赏
  • 举报
回复
+
[Quote=引用 9 楼 zhongqixing1104 的回复:]
$header = "GET /CRM/test2.php HTTP/1.1\r\n";
你这个是get方式传数据,get方式数据是放到url上传的,$header = "GET /CRM/test2.php?xx=xx&xx=xx HTTP/1.1\r\n";

或者你改成post方式,取数据的时候用post方式。
[/Quote]
fxs_2008 2011-01-07
  • 打赏
  • 举报
回复
写的不对,肯定能得到返回值的。

不能跳转,它不是浏览器。它只是请求并得到响应串!
zhongqixing1104 2011-01-07
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 heroblues 的回复:]

谢谢楼上的。那页面能同时跳转到tets2.php页面吗?
[/Quote]
不会跳转
kingfly1818 2011-01-07
  • 打赏
  • 举报
回复
当然不能,如果要跳转的话,就不要模拟http提交,直接跳转到test2.php?+参数
heroblues 2011-01-07
  • 打赏
  • 举报
回复
谢谢楼上的。那页面能同时跳转到tets2.php页面吗?
zhongqixing1104 2011-01-07
  • 打赏
  • 举报
回复
$header = "GET /CRM/test2.php HTTP/1.1\r\n";
你这个是get方式传数据,get方式数据是放到url上传的,$header = "GET /CRM/test2.php?xx=xx&xx=xx HTTP/1.1\r\n";

或者你改成post方式,取数据的时候用post方式。
xiexiaokang 2011-01-07
  • 打赏
  • 举报
回复
post提交表单要用$_POST,$_REQUEST[]都可以用,$_GET只能用于get方式提交的表单……
heroblues 2011-01-07
  • 打赏
  • 举报
回复
高人都去哪里了?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧