1.通过curl函数
$post_data = array();
$post_data['clientname'] = "test08";
$post_data['clientpasswd'] = "test08";
$post_data['submit'] = "submit";
$url='http://xxx.xxx.xxx.xx/xx/xxx/top.php';
$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);
//为了支持cookie
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = curl_exec($ch);
2.通过fsockopen.
$URL=‘http://xxx.xxx.xxx.xx/xx/xxx/top.php';
$post_data['clientname'] = "test08";
$post_data['clientpasswd'] = "test08";
$post_data['submit'] = "ログイン";
$referrer="";
// parsing the given URL
$URL_Info=parse_url($URL);
// Building referrer
if($referrer=="") // if not given use this script as referrer
$referrer=$_SERVER["SCRIPT_URI"];
// making string from $data
foreach($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);
分享到:
相关推荐
php模拟POST提交的4种方法.pdf
PHP基于curl模拟post提交json数据示例.docx
本篇文章是对php模拟POST提交的2种方法进行了详细的分析介绍,需要的朋友参考下
主要介绍了PHP基于curl模拟post提交json数据操作,结合实例形式分析了php使用curl实现post方式提交json数据相关操作步骤与注意事项,代码简单实用,需要的朋友可以参考下
本文实例讲述了php模拟post提交数据的方法。分享给大家供大家参考。具体如下: php模拟post提交数据,用处很多,可用来网站的采集,登陆等等 这里以我项目中的论坛登录为例加以说明: 复制代码 代码如下:function A_...
PHP版SOCKET模拟提交POST消息 模拟邮箱登陆什么的就可以做了。
下面软件开发网小编给大家整理了三种php模拟post传值的方法,file_get_contents、curl和socket。 第一种:file_get_contents来模拟post <php xss=removed xss=removed> array( ‘method‘=>‘POST‘, ‘content‘=>...
本文主要介绍了php curl模拟post提交数据的方法,大家参考使用吧
介绍一个发送POST请求的三种方式的php类,PHP发送POST请求的三种方式 分别使用curl file_get_content fsocket 来实现post提交数据。
php模拟post提交请求,调用接口 /** * 模拟post进行url请求 * @param string $url * @param string $param */ function request_post($url = '', $param = '') { if (empty($url) || empty($param)) { ...
php模拟表单上传图片 POST ,做一个b.php,接收数据
php CURL函数可以模仿用户进行一些操作,如我们可以模仿用户提交数据也可以模仿用户进行网站访问了,下面我们来介绍利用CURL模拟进行微信接口的GET与POST例子,例子非常的简单就两个大家一起看看.
通用的http请求工具,可以模拟表单提交、上传文件、发送请求、获取网页内容