
已解决问题
谷歌jazz0o用户在2019.06.06提交了关于“鲁迅简介php实现模拟post请求用法实例”的提问,欢迎大家涌跃发表自己的观点。目前共有1个回答,最后更新于2024-12-25T00:17:35。希望大家能够帮助她。详细问题描述及疑问:期待您的答案,滴水之恩,来日我当涌泉相报 !
详细问题描述及疑问:期待您的答案,滴水之恩,来日我当涌泉相报 !
本文实例讲述了php实现模拟post请求的方法。分享给大
class
Request{
public
static
function
post($url
$post_data
=
'',
=
5){//curl
$ch
=
curl_init();
curl_setopt
($ch,
CU
$u
curl_setopt
($ch,
CURLOPT_POST,
1);
if($post_data
!=
'')
curl_setopt($c
CURLOPT_POSTFIELDS,
$
}
curl_setopt
($c
CURLOPT_
1);
curl_setopt
($ch,
CURLOPT_CONNECTTIMEO
$timeout);
curl_
CURLO
false);
$file_contents
=
curl_exec($c
curl_close($ch);
return
$file_c
}
public
static
functio
post2($url,
$data=array()
$postdata
=
http_build_qu
$data
);
$opts
=
array('http'
=>
arra
'method'
=>
'POST',
'header'
=>
'Content
applicati
'content'
=>
$
)
);
$context
=
s
$
=
file_get_contents($url,
false,
$context);
r
$result;
}
public
static
func
post3($host,$path,$query,$others=''){//fsocket
$post="POST
$path
h**TTP/1.1\r\nh**ost:
$host\r\n";
$post.="Content-type:
application/
$post.="User
Mozilla
4.0\r\nC
";
$post
close\r\n\r\n$query";
$h=fsockopen($host,80);
fwrite($h,$post);
for($a=0,$
$b=fread
$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程序设计有所帮助。