• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php 模拟POST提交的2种方法详解_php技巧

php 搞代码 3年前 (2022-01-26) 16次浏览 已收录 0个评论

一、通过curl函数

$post_data = array();<BR>$post_data['clientname'] = "test08";<BR>$post_data['clientpasswd'] = "test08";<BR>$post_data['submit'] = "submit";<BR>$url='http://xxx.xxx.xxx.xx/xx/xxx/top.php';<BR>$o="";<BR>foreach ($post_data as $k=>$v)<BR>{<BR>    $o.= "$k=".urlencode($v)."&";<BR>}<BR>$post_data=substr($o,0,-1);<BR>$ch = curl_init();<BR>curl_setopt($ch, CURLOPT_POST, 1);<BR>curl_setopt($ch, CURLOPT_HEADER, 0);<BR>curl_setopt($ch, CURLOPT_URL,$url);<BR>//为了支持cookie<BR>curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');<BR>curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);<BR>$result = curl_exec($ch);<BR>


二、通过fsockopen

$URL=‘http://xxx.xxx.xxx.xx/xx/xxx/top.php';<BR>$post_data['clientname'] = "test08";<BR>$post_data['clientpasswd'] = "test08";<BR>$post_data['submit'] = "ログイン";<BR>$referrer="";<BR>// parsing the given URL<BR>$URL_Info=parse_url($URL);<BR>// Building referrer<BR>if($referrer=="") // if not given use this script as referrer<BR>$referrer=<PRE class="php">{1}


SERVER["SCRIPT_URI"]; // making string from $dataforeach($post_data as $key=>$value)$values[]="$key=".urlencode($value); $data_string=implode("&",$values);// Find out which port is needed - if not given use standard (=80)if(!isset($URL_Info["port"]))$URL_Info["port"]=80;//
building POST-request:$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";$fp = fsockopen($URL_Info["host"],$URL_Info["port"]);fputs($fp, $request);while(!feof($fp)) { $result .= fgets($fp, 128);}fclose($fp);




Snoopy 类(2)

sourceforge.net/p

5本文来源gao!daima.com搞$代!码#网#

搞代gaodaima码

rojects/snoopy/


http://www.redalt.com/xref/trunk/nav.htm?wp-includes/class-snoopy.php.htm


HTTP类(1,2)


http://www.phpclasses.org/browse/download/1/file/5/name/http.php


PEAR HTTP_Request


http://pear.php.net/package/HTTP_Request


Popularity: 70%




搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php 模拟POST提交的2种方法详解_php技巧
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址