php处理post请求,并返回json

<?php

function Post( $url, $post = null)
{
$context = array();
if ( is_array( $post))
{
ksort( $post);
         $context = array(
             'http' => array(
                 'timeout'=> 60,
                 'method' => 'POST',
                 'header' => "Content-type: application/x-www-form-urlencoded ",
          'content' => http_build_query( $post),                          
            ),
        );
}
return file_get_contents( $url, false, stream_context_create( $context));
}
$data = array
(
'parm1' => '1' ,
'parm2' => '2',
'parm3' => '3',
);
echo Post( 'this is your url', $data);
? >

猜你喜欢

转载自blog.csdn.net/young_gao/article/details/80193751
今日推荐