PHP 使用 curl 提交 json 格式数据

发表日期:2021-06-28 14:01:20 | 来源: | | 浏览(642) 分类:PHP杂项

01function curl_post_json($url$data array())
02    {
03 
04        $ch = curl_init();
05 
06        curl_setopt($ch, CURLOPT_URL, $url);
07 
08        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
09 
10        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
11 
12        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
13 
14        curl_setopt($ch, CURLOPT_POST, 1);
15 
16        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
17 
18        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
19                'Content-Type: application/json; charset=utf-8'
20            )
21        );
22 
23        $output = curl_exec($ch);
24 
25        curl_close($ch);
26 
27        return $output;
28 
29    }


集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。