php 模拟POST提交的2种方法详解
前端之家收集整理的这篇文章主要介绍了
php 模拟POST提交的2种方法详解,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_0@
<FONT style="COLOR: #ff0000">一、通过curl函数
<div class="codetitle">
<a style="CURSOR: pointer" data="88885" class="copybut" id="copybut88885" onclick="doCopy('code88885')"> 代码如下: <div class="codebody" id="code88885">
$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,-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);