您好,欢迎访问一九零五行业门户网

php通过http post发送json数据

通过http post发送json数据
function http_post_data($url, $data_string) { $ch = curl_init(); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_postfields, $data_string); curl_setopt($ch, curlopt_httpheader, array( 'content-type: application/json; charset=utf-8', 'content-length: ' . strlen($data_string)) ); ob_start(); curl_exec($ch); $return_content = ob_get_contents(); ob_end_clean(); $return_code = curl_getinfo($ch, curlinfo_http_code); return array($return_code, $return_content);}$url = http://xx.xx.cn;$data = json_encode(array('a'=>1, 'b'=>2));list($return_code, $return_content) = http_post_data($url, $data);
其它类似信息

推荐信息