PHP post请求接口 header设置
- A
调用 public function test(){ $data = array( "name"=>'123123', "password"=>'123123', ); $url = 'https://www.recho.cn'; $header[] = 'content-type: application/json'; $a = $this->http_requests($url,$header,$data); }
function http_requests($url,$header= array(),$data = array()){ $oCurl = curl_init(); curl_setopt($oCurl, CURLOPT_URL, $url); curl_setopt($oCurl, CURLOPT_HTTPHEADER, $header); //关闭https验证 curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false); $data = json_encode( $data ,JSON_UNESCAPED_UNICODE ); curl_setopt($oCurl,CURLOPT_POST,true); curl_setopt($oCurl,CURLOPT_POSTFIELDS,$data); //至关重要,CURLINFO_HEADER_OUT选项可以拿到请求头信息 curl_setopt($oCurl, CURLINFO_HEADER_OUT, TRUE); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($oCurl, CURLOPT_POSTFIELDS, $bodystr); $sContent = curl_exec($oCurl); //通过curl_getinfo()可以得到请求头的信息 $a=curl_getinfo($oCurl); return $sContent; //var_dump($sContent);die; }
觉得本章能帮助到您,记得转发分享哦!
傲世》原创,转载请保留文章出处。
本文链接:https://www.recho.cn/29.html
如您对本文章内容有所疑问、反馈或补充,欢迎通过邮箱:[email protected] 联系我们!
版权声明:若无特殊注明,本文为《正文到此结束