php服务器网络请求

1,get方法

$result = file_get_contents($personUrl);

2,post方法,使用querystring,使用json

$personUrl="http://www.wacloud.net/open/persion/insert?appid=$doorAppid&sign=$sign&timestamp=$timestamp";

$info=array(
'canAttence'=>true,
'canPass'=>true,
'card'=>$cardNum,
'deptIdList'=>[6330],
'effectEndTime'=>"2019-07-28 02:10:39.305Z",
'effectStartTime'=>"2019-07-20 02:10:39.305Z",
'mobile'=>"18866668888",
'name'=>"临时访客",
'openType'=>2,
'persionType'=>2,
'status'=>0,
);

$context = stream_context_create(array(
'http' => array('method' => 'POST',
'header' => 'Content-Type:application/json',
'content' => json_encode($info),
'timeout' => 20 )
));

$context = stream_context_create(array( 
'http' => array('method' => 'POST',
'header' => 'Content-Type:application/x-www-form-urlencoded',

'content' => http_build_query($info), 

'timeout' => 20 ) 
)); 
$result = file_get_contents($personUrl,false, $context);



print_r($result);

http_build_query
原文地址:https://www.cnblogs.com/bluestear/p/11228211.html