1. public function http_post_json($url, $jsonStr)
    2. {
    3. //print($jsonStr.'<br/>');
    4. $ch = curl_init();
    5. curl_setopt($ch, CURLOPT_POST, 1);// 发送一个常规的Post请求
    6. curl_setopt($ch, CURLOPT_URL, $url);// 要访问的地址
    7. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检测
    8. curl_setopt($ch, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循
    9. curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
    10. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    11. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    12. 'Content-Type: application/json;charset=UTF-8',
    13. 'Content-Length: ' . strlen($jsonStr)
    14. )
    15. );
    16. $response = curl_exec($ch);
    17. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    18. if (curl_errno($ch)) {
    19. throw new Exception(curl_error($ch));
    20. }
    21. curl_close($ch);
    22. return array($httpCode, $response);
    23. }