首页 > 后端开发 > php教程 > [php]通过http post发送json数据

[php]通过http post发送json数据

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-07-29 09:13:09
原创
1144 人浏览过
function http_post_data($url, $data_string) {  
  
        $ch = curl_init();  
        curl_setopt($ch, CURLOPT_POST, 1);  
        curl_setopt($ch, CURLOPT_URL, $url);  
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);  
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(  
            'Content-Type: application/json; charset=utf-8',  
            'Content-Length: ' . strlen($data_string))  
        );  
        ob_start();  
        curl_exec($ch);  
        $return_content = ob_get_contents();  
        ob_end_clean();  
  
        $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);  
        return array($return_code, $return_content);  
    }  
  
$url  = "http://xx.xx.cn";  
$data = json_encode(array('a'=>1, 'b'=>2));   
  
list($return_code, $return_content) = http_post_data($url, $data);  
登录后复制

以上就介绍了[php]通过http post发送json数据,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
PHP中return '' 和return区别
来自于 1970-01-01 08:00:00
0
0
0
return 的用法
来自于 1970-01-01 08:00:00
0
0
0
return的使用
来自于 1970-01-01 08:00:00
0
0
0
关于laravel中的return方法
来自于 1970-01-01 08:00:00
0
0
0
为什么return不了数据给ajax
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板