您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 铁岭分类信息网,免费分类信息发布

php 模拟POST提交的2种方法详解_PHP教程

2024/10/20 5:23:31发布12次查看
一、通过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);
二、通过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={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/projects/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%
http://www.bkjia.com/phpjc/327596.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/327596.htmltecharticle一、通过curl函数 复制代码 代码如下: $post_data = array(); $post_data['clientname'] = test08; $post_data['clientpasswd'] = test08; $post_data['submit'] = submit;...
铁岭分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录