public function sendPost()
{
$url = 'http://xxx.xxxx.com';
$post_data = [
'data1' => '',
'data2' => '',
'data3' =>''
];
$options = array(
'http' => array(
'method' => 'POST',
// header 需要设置为 JSON
'header' => 'Content-type:application/json',
'content' => json_encode($post_data,true),
// 超时时间
'timeout' => 60
)
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
return $result;//返回数据格式为json
}