时间戳没问题但一直提示参数错误?
URL:
"https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token="+accessToken;
JSON:
{
"name": "测试",
"coverImg": "NeUgZKL1Q1VQ_vKewVyUjteHNa-tRBcVGBU5IRCwd2dBkpXBmGtaltwVILvWfC5O",
"startTime": 1592534352,
"endTime": 1592537952,
"anchorName": "老八",
"anchorWechat": "ddssaa135",
"shareImg": "4WsC6BwTu2p9RG8Q6WH0kQufJm4wbZA8dpPGrsop7h0KW3npLRPqnR2Zj0HOUJj4",
"type": 0,
"screenType": 0,
"closeLike": 0,
"closeGoods": 0,
"closeComment": 0
}
请求头:
post.addHeader("Accept", "application/json");
post.addHeader("Content-Type", "'application/json';charset='utf-8'");
post.addHeader("Cache-Control", "no-cache");
post.addHeader("Pragma", "no-cache");
遇到同样的问题,需要在调用接口时对CURL做以下设置(亲测通过):
$headers = [ "Content-Type: application/json", "Accept: application/json", ]; curl_setopt( $oCurl, CURLOPT_HTTPHEADER , $headerParams );
加了请求头还是报时间格式错误,有解决办法吗
/** * POST请求-简单数据 * @param $url * @param $data * @return mixed */ private function _requestPost($url,$data){ $headerArray =array("Content-type:application/json;charset='utf-8'","Accept:application/json"); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return json_decode($output,true); }
请问楼主解决了吗?
php的解决方法:
增加header
$headers = array( "Content-Type: application/json", "Accept: application/json", );
解决了,消息体不需要设置contentType,为啥报参数错误-_-|| StringEntity entity = new StringEntity(json, "UTF-8"); //entity.setContentType(new BasicHeader("application/json","UTF-8")); post.setEntity(entity);
时间戳有10位和13位的。你试试13位的