Home >Backend Development >PHP Tutorial >php post json data

php post json data

WBOY
WBOYOriginal
2016-07-25 08:43:141465browse
  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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn