您好,欢迎访问一九零五行业门户网

调用API,对方总是说参数放在BODY里面

请问php curl post json参数如何放在body里面
private function getaccesstoken(){
$url='http://114.215.198.210:8081/api_v1/oauth2/accesstoken'; $postdata=array('client_id'=>$this->cliendid,'client_secret'=>$this->client_secret,'grant_type'=>'client_credentials'); echo $postjosndata = json_encode($postdata); $ch = curl_init($url); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $postjosndata); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, false); $data = curl_exec($ch); return $data; }

没错吧?对方总是说请求参数要放在body里面
回复内容: 请问php curl post json参数如何放在body里面
private function getaccesstoken(){
$url='http://114.215.198.210:8081/api_v1/oauth2/accesstoken'; $postdata=array('client_id'=>$this->cliendid,'client_secret'=>$this->client_secret,'grant_type'=>'client_credentials'); echo $postjosndata = json_encode($postdata); $ch = curl_init($url); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $postjosndata); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, false); $data = curl_exec($ch); return $data; }

没错吧?对方总是说请求参数要放在body里面
新增下面这句试试
curl_setopt($ch, curlopt_httpheader, array( 'content-type: application/json', 'content-length: ' . strlen($postdata)) );
post请求body一般有两种格式,json和form。你用的json,可能对方用的form
php不懂,不过request的时候是可以把数据放到request body里的,看这个
http://stackoverflow.com/ques...
其它类似信息

推荐信息