php post 提交json包,返回false ,怎么回事?
php post 提交json包,返回false ,怎么回事?
/**
* PHP发送Json对象数据
*
* @param $url 请求url
* @param $data_string发送的json字符串
* @return array
*/
function http_post_data($url, $data_string) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
return $result;
}