Finishing off a slight curl function

IF (! function_exists ( 'curlRequest' )) 
{ 
    / * * 
    * the cURL request 
    * @author ligeliang 
    * @param [type] $ URL [Description] 
    * @param [type] $ Data is empty get request, the request is not empty post 
    @return * [type] [Description] 
    * / 
    function curlRequest ( $ URL , $ Data = null ) 
    { 
        // initialization 
        $ CH = curl_init ();
         // set crawl URL 
        curl_setopt ( $ CH , CURLOPT_URL to, $ URL ) ; 

        // message header is provided as a data stream output
        curl_setopt ( $ CH , CURLOPT_HEADER, 0 );
         // set the information acquired as a return stream file, instead of being output. 
        curl_setopt ( $ CH , CURLOPT_RETURNTRANSFER,. 1 ); 

        // get the whole is equal to 0, to avoid the special case of containing the url parameter https 
        IF ( the strpos ( $ url , 'https: //') === 0 ) { 
            curl_setopt ( $ CH , CURLOPT_SSL_VERIFYPEER, FALSE ); // HTTPS request does not verify the certificate 
            curl_setopt ( $ CH , CURLOPT_SSL_VERIFYHOST, FALSE ); // HTTPS request does not verify that the hosts 
        } 

        IF ! ( empty( $ Data )) {
             // set post submission 
            curl_setopt ( $ CH , CURLOPT_POST,. 1 );
             // Set the post data 
            curl_setopt ( $ CH , CURLOPT_POSTFIELDS, http_build_query ( $ Data )); 
        } 

        // Run 
        $ Data = the curl_exec ( $ CH );
         // Close URL request 
        curl_close ( $ CH );
         return  $ Data ; 
    } 
}

 

Guess you like

Origin www.cnblogs.com/songkaixin/p/11126840.html