首页 >后端开发 >php教程 >php post json数据

php post json数据

WBOY
WBOY原创
2016-07-25 08:43:141439浏览
  1. function http_post_data($url, $data_string) {
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_POST, 1);
  4. curl_setopt($ch, CURLOPT_URL, $url);
  5. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  6. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  7. 'Content-Type: application/json; charset=utf-8',
  8. 'Content-Length: ' . strlen($data_string))
  9. );
  10. ob_start();
  11. curl_exec($ch);
  12. $return_content = ob_get_contents();
  13. ob_end_clean();
  14. $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  15. return array($return_code, $return_content);
  16. }
  17. $url = "http://www.xxxx.com";
  18. $data = json_encode(array('cmd'=>"Query_Ranking_Sys",'group'=>1,'room'=>0,'name'=>"RoomSvr",'value'=>array(0=>array('key'=>5,'beginindex'=>0,'count'=>10))));
  19. list($return_code, $return_content) = http_post_data($url, $data);
复制代码

php, post, json


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn