Use curl to call interface data in thinkphp5.0

Hits: 0

//The first data calling method 
         $arr = array ( "a" => "123456" , "b123456" => "zhaotoubiao" );
          //Interface address and token 
         $url = 'https://address?token= token' ;
         $ch = curl_init();

         //Set the post method to submit 
         curl_setopt($ch, CURLOPT_POST, 1 );
          //Set the fetched url
         curl_setopt($ch, CURLOPT_URL, $url);
         //set post data
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
         //Do not do certificate verification, deploy in linux environment and change to true 
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false );
          //Set header file information as data stream output 
         curl_setopt($ch, CURLOPT_HTTPHEADER, array (
                  'Content-Type: application/json; charset=utf-8' ,
                  'Content-Length : ' . strlen($data_string))
          //Excuting an order

         $return_content = ob_get_contents();
         $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

Note: 1. The token in the address in the code

2. The data was empty when it was first made. Later, after adding these two lines of code, the ssl certificate verification data came out (I tested it locally), and it was opened normally on the server.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

Leave a Reply

Your email address will not be published.