$params=[ "a"=>"test", "b"=>"测试" ]; $header=[ "Content-Type: application/json; charset=utf-8", "host: www.baidu.com" ]; $url="https://www.baidu.com/path"; $req = curl_init(); curl_setopt($req, CURLOPT_URL, $url); //url设置 curl_setopt($req, CURLOPT_HTTPHEADER, $header); curl_setopt($req, CURLOPT_HEADER, 0); curl_setopt($req, CURLOPT_RETURNTRANSFER, 1); curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($req, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($req, CURLOPT_TIMEOUT, 10); if (strtolower($method) == "post") { curl_setopt($req, CURLOPT_POST, 1); // post方法 curl_setopt($req, CURLOPT_POSTFIELDS, json_encode($params,320)); // post的变量 } $data = curl_exec($req);
标签:请求,url,req,post,curl,CURLOPT,setopt From: https://www.cnblogs.com/boye169/p/17170802.html