60, " />
牛骨文教育服务平台(让学习变的简单)
博文笔记

PHP给第三方接口POST或GET方式传输数据并得到返回值

创建时间:2015-12-12 投稿人: 浏览次数:11800

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.baidu.com", $data);


阅读更多
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。