fsockopen的get和post实例

<?php
/*
**GET 提交
*/
/*
$f=fsockopen(");
$content='';
fwrite($f,"GET / HTTP/1.1\r\n");//设置请求方式
fwrite($f,"Host:www.baidu.com\r\n");
fwrite($f,"Connection:close\r\n\r\n");
while(($line=fread($f,8192))){
 $content.=$line;
}
fclose($f);
echo $content;
*/

//post提交,必须要注意的是:post数据必须要要进行rawurlencode转换,必须提交content-length的长度,post表单必须跟在\r\n\r\n

$data=rawurlencode("name").'='.rawurlencode('guoxu');
$f=fsockopen("127.0.0.1",80,$error,$errstr,60);
fwrite($f,"POST /ob/post.php?ac=post HTTP/1.1\r\n");
fwrite($f,"Host:127.0.0.1\r\n");
fwrite($f,"Content-Type:application/x-www-form-urlencoded\r\n");
fwrite($f,"Content-Length:".strlen($data)."\r\n");
fwrite($f,"Connection:Close\r\n");
fwrite($f,"Accept:*/*\r\n\r\n");
fwrite($f,$data."\r\n");
fwrite($f,"\r\n");
$str='';

while(($line=fread($f,1024))){
 $str.=$line; 
}
fclose($f);
$array=split("\n\r",$str,2);
echo $array[1];
?>

转载于:https://www.cnblogs.com/itfenqing/archive/2011/09/20/4429502.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值