private static function curlJson($url, $data_string, $header = array() )
{
$header[] = 'Expect:';
$header[] = 'X-AjaxPro-Method:ShowList';
$header[] = 'Accept: application/json,*/*';
$header[] = 'Content-Type: application/json; charset=utf-8';
$header[] = 'Content-Length: ' . strlen($data_string);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADERFUNCTION,
function ($curl, $header) use (&$headers) {
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) // ignore invalid headers
return $len;
$headers[strtolower(trim($header[0]))] = trim($header[1]);
return $len;
}
);
$res = array();
$res['data'] = curl_exec($ch);
curl_close($ch);
$res['headers'] = $headers;
return $res;
}
curl json数据并获取返回响应头header信息
最新推荐文章于 2025-02-27 09:52:37 发布