PHP通过Http Post请求发送Json对象数据

阅读更多
public static  function httpPostJson($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);
}


http://blog.csdn.net/u014646984/article/details/45765947

你可能感兴趣的:(PHP通过Http Post请求发送Json对象数据)