php Curl json

来源:互联网 发布:微信软文软件 编辑:程序博客网 时间:2024/06/11 13:52

代码

//post json 请求function http_post_json($url, $jsonStr){  $ch = curl_init();  curl_setopt($ch, CURLOPT_POST, 1);  curl_setopt($ch, CURLOPT_URL, $url);  curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  curl_setopt($ch, CURLOPT_HTTPHEADER, array(      'Content-Type: application/json; charset=utf-8',      'Content-Length: ' . strlen($jsonStr)    )  );  $response = curl_exec($ch);  $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);  return array($httpCode, $response);}