首页 > 其他分享 >post row 请求数据

post row 请求数据

时间:2022-10-25 14:34:15浏览次数:51  
标签:SendDataRowByCurl 请求 curl header post port CURLOPT row

控制器

    protected $accessTokenUrl = "http://www.xxxxx.com:8888/dw/dahua/accesstoken.php";
    public function getaccessToken(){
        $AppKey = Config::get(['name'=>"monitorAppKey"]);
        $AppSecret = Config::get(['name'=>"monitorAppSecret"]);
        $access=[
            'AppKey'=>$AppKey->value,
            'AppSecret'=>$AppSecret->value,
        ];
        $port = "8888";
        $accessTokens = SendDataRowByCurl($this->accessTokenUrl,$port,"POST",true,$access);
        $data = json_decode($accessTokens);
        return $data;
    }

curl POST方式row请求数据

 1 if (!function_exists('SendDataRowByCurl')) {
 2     function SendDataRowByCurl($url, $port, $post = '', $header = array())
 3     {
 4         $curl = curl_init();
 5         $header =json_encode($header);
 6         curl_setopt_array($curl, [
 7             CURLOPT_PORT => "{$port}",
 8             CURLOPT_URL => "{$url}",
 9             CURLOPT_RETURNTRANSFER => true,
10             CURLOPT_ENCODING => "",
11             CURLOPT_MAXREDIRS => 10,
12             CURLOPT_TIMEOUT => 30,
13             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
14             CURLOPT_CUSTOMREQUEST => "{$post}",
15             CURLOPT_POSTFIELDS => "{$header}",
16         ]);
17         $response = curl_exec($curl);
18         if (curl_error($curl)) {
19             return 'cURL Errno' . curl_error($curl);
20         }
21         curl_close($curl);
22         return $response;
23     }
24 }

 

标签:SendDataRowByCurl,请求,curl,header,post,port,CURLOPT,row
From: https://www.cnblogs.com/sjiatong/p/16824734.html

相关文章