接口在postman里面测试是成功的。但是PHP curl post这个 接口竟然失败
后面想明白了。请求头的原因。这个接口的请求头是x-www-form-urlencoded。所以curl post也要改成这样
if($url == "" || $timeout <= 0){ return false; } $post_data = http_build_query($post_data);//重点 $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0);//不抓取头部信息。只返回数据 curl_setopt($curl, CURLOPT_TIMEOUT, (int)$timeout);//超时设置 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//1表示不返回bool值 curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));//重点 curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); $data = curl_exec($curl); if (curl_errno($curl)) { return curl_error($curl); } curl_close($curl);
评论回复