php两次post_phpcurlpost

function poster() {$URL = 'http://www.yw56.com.cn/DIY.asp'; //需要提交到php两次post的页面//下面这段是要提交的数据$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提交数据后php两次post,之后的操作就不用我们不管php两次post了,//这里就是在模拟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的用法就这样子php两次post了,不做多说明$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'] = "提交";$url='http://www.yw56.com.cn/DIY.asp';$cookie="ASPSESSIONIDQASTTQBC=NCCPADLCAKFNICPOABDAFHOP";$o="";foreach ($post_data as $k=>$v) {$o.= "$k=".urlencode($v)."&"; }$post_data=substr($o,0,-1);$ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL,$url);//为php两次post了支持cookie curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);$result = curl_exec($ch);echo $result; }

php两次post_phpcurlpost

转自:https://blog.csdn.net/bidong77/article/details/5004581

php两次post_phpcurlpost

发布于 2024-07-29 18:07:22
收藏
分享
海报
0 条评论
37
目录

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~