开发项目中,遇到需要向第三方接口发送json数据数据的情况,php默认发送数据形式为text,需要告诉第三方接口数据形式为json,这时就需要执行下列代码修改http Content-Type头信息
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($jsonStr)
)
);
参考网址:https://www.cnblogs.com/52php/p/5677684.html
https://blog.csdn.net/hai7425/article/details/70849448