本文共 1051 字,大约阅读时间需要 3 分钟。
重点在curl中指定 Content-Type: application/json; charset=utf-8
"e10adc3949ba59abbe56e057f20f883e", "username"=>"canlang" ); $data = json_encode($param); list($return_code,$headers,$return_content) = http_post_data($url, $data);print_r($return_content);exit; 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_HEADER, TRUE); //表示需要response header 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(); //获取头部 $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $headers = substr($return_content, 0, $header_size); //http状态码 $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); return array($return_code, $headers,$return_content);}
转载地址:http://codrj.baihongyu.com/