已解决问题
谷歌jazz0o用户在2019.06.06提交了关于“htcphp实现模拟post请求用法实例”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2023-11-30T14:52:11。希望大家能够帮助她。详细问题描述及疑问:期待您的答案,当代劳模,所有人都应该向你学习 !
详细问题描述及疑问:期待您的答案,当代劳模,所有人都应该向你学习 !
本文实例讲述了php实现模拟p
Reque
publi
static
funct
post($url,
$post_data
=
'',
$timeou
=
5){//curl
$ch
=
curl_init();
curl_setopt
($ch,
CURLOPT_URL,
$
curl_setopt
($ch
CURLOPT_POST,
1);
if($
''){
curl_setopt($ch,
$post_data)
}
curl_setopt
($
CURLOPT_RETURN
1);
c
($
CURLOPT
$timeout
curl_se
CURLOP
false);
$file_contents
=
curl_exec($ch);
curl_c
return
$file_c
}
public
static
function
post2($url,
$data
$postdata
=
http_build_query(
$data
);
$
=
array('http'
=>
arra
'method'
=>
'POST',
'header'
=>
'Content-type:
application/x-www-form-urlen
'content'
=>
$postdata
)
);
$context
=
stream_cont
$result
=
file_get_contents($url,
false,
$context);
return
$result;
}
publ
static
function
post3($host,$path,$query,$others=''){//fsocket
$post="P
$path
h**TTP/1.1\r\nh**ost:
$host\r\n";
$post.="Content-type:
application/x-www-form-";
$post.="urlencoded\r\n${others}";
$post.="User-Agent:
Mozilla
4.0\r\nContent-length:
";
$post.=strlen($query)."\r\nConnection:
close\r\n\r\n$query";
$h=fsockopen($host,80);
fwrite($h,$post);
for($a=0,$r='';!$a;){
$b=fread($h,8192);
$r.=$b;
$a=(($b=='')?1:0);
}
fclose($h);
return
$r;
}
}
$url='http://******/con/Inter.php';
$data=Request::post($url,array('api'=>'tag_list'));
$data2=Request::post2($url,array('api'=>'tag_list'));
echo
$data;
希望本文所述对大家的php程序设计有所帮助。