file_get_post实现post请求

function Post($url, $post = null){
    $context = array();
    if (is_array($post)) {
      ksort($post);
 
      $context['http'] = array (
        'timeout'=>60,
        'method' => 'POST',
        'content' => http_build_query($post, '', '&'),
       );
    }
 
    return file_get_contents($url, false, stream_context_create($context));
}
 
$data = array (
    'name' => 'test',
    'email' => 'test@gmail.com',
    'submit' => 'submit',
);
 
echo Post('http://www.jb51.net', $data);
posted @ 2017-05-12 06:39  戈丫汝  阅读(139)  评论(0编辑  收藏  举报