PHP curl POST请求


function
curlQytl($url,$data,$type = ‘form‘,$token=null){ if($type==‘form‘){ $headers = array( ‘Content-Type: application/x-www-form-urlencoded‘ ); }else{ $headers = array( ‘Content-Type: application/json‘, ‘Authorization: ‘ . $token[‘token_type‘].‘ ‘.$token[‘access_token‘]// 第三方验证 ); } if(is_array($data)){ $data = json_encode($data); } $curl = curl_init(); //请求地址 curl_setopt($curl, CURLOPT_URL, $url); //头部验证 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); //头部验证 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); //是否返回结果 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //请求超时设置(单位秒,0不做限制) // curl_setopt($curl, CURLOPT_TIMEOUT, 0); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10000); //https请求,(false为https) curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //请求方式POST curl_setopt($curl, CURLOPT_CUSTOMREQUEST, ‘POST‘); //参数设置 curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //执行 $response = curl_exec($curl); //关闭 curl_close($curl); //返回 return $response; }
第一种type=‘form‘参数 $data = ‘username=[mrwang]&password=[123456]‘; 不用括号

PHP curl POST请求

上一篇:Flume+Morphlines实现数据的实时ETL


下一篇:自动发布.NET Core Web应用