php模拟用户进行post,PHP 模拟 Post 的两种方法

function poster()

{

$URL = 'http://www.yw56.com.cn/DIY.asp'; //需要提交到的页面

//下面这段是要提交的数据

$post_data['orderid'] = "YW861736303CN";

$post_data['button'] = "提交";

$referrer="http://www.yw56.com.cn/DIY.asp";

$Cookie="ASPSESSIONIDQASTTQBC=NCCPADLCAKFNICPOABDAFHOP";

$URL_Info=parse_url($URL);

if($referrer=="")

{

$referrer=$_SERVER["SCRIPT_URI"];

}

foreach ($post_data as $key=>$value)

{

$values[]="$key=".urlencode($value);

}

$data_string=implode("&",$values);//提交的数据格式是 a=1&b=2

// Find out which port is needed - if not given use standard (=80)

if (!isset($URL_Info["port"])) {

$URL_Info["port"]=80;

// building POST-request:

//一般做网站用form提交数据后,之后的操作就不用我们不管了,

//这里就是在模拟POST操作的HTTP头,具体的可以去查HTTP协议的资料,并不复杂

$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";

$request.="Host: ".$URL_Info["host"]."\n";

$request.="Referer: $referrer\n";

$request.="Content-type: application/x-www-form-urlencoded\n";

$request.="Content-length: ".strlen($data_string)."\n";

$request.="Connection: close\n";

$request.="\n";

$request.=$data_string."\n";

//exit;

}

//fsockopen的用法就这样子了,不做多说明

$fp = fsockopen($URL_Info["host"], $URL_Info["port"]);

fputs($fp, $request);//把HTTP头发送出去

while(!feof($fp)) {

//$result 是提交后返回的数据

$result .= fgets($fp, 1024);

}

fclose($fp);

echo $result;

}

function poster1()

{

$post_data = array();

$post_data['orderid'] = "YW861736303CN";

$post_data['button'] =

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值