日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
PHP語(yǔ)言中phpcurl的幾種應(yīng)用方式

我們通過對(duì)PHP開發(fā)基礎(chǔ)入門這一專題的學(xué)習(xí)可以了解到,PHP語(yǔ)言的一些具體概念的實(shí)際應(yīng)用。今天我們向大家介紹的是在PHP中的php curl的幾種使用方式,希望對(duì)有需要的朋友有所幫助。

#t#1. php curl的默認(rèn)調(diào)用方法,get方式訪問url

 
 
 
  1. ....     
  2.     $ch = curl_init();     
  3.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//設(shè)置http頭     
  4.     curl_setopt($ch, CURLOPT_ENCODING, "gzip" ); 
    //設(shè)置為客戶端支持gzip壓縮     
  5.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30 ); 
    //設(shè)置連接等待時(shí)間     
  6.     curl_setopt($ch, CURLOPT_URL, $url );     
  7.     curl_exec( $ch );     
  8.     if ($error = curl_error($ch) ) {     
  9.         //出錯(cuò)處理     
  10.         return -1;     
  11.     }     
  12.     fclose($fp);       
  13.     
  14.     $curl_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    //獲取http返回值     
  15.     if( $curl_code == 200 ) {     
  16.         //正常訪問url     
  17.     }     
  18.     //異常     
  19. ....    

2. 設(shè)置http header支持php curl訪問lighttpd服務(wù)器

 
 
 
  1. $header[]= 'Expect:';  

3. 設(shè)置curl,只獲取http header,不獲取body:

 
 
 
  1. curl_setopt($ch, CURLOPT_HEADER, 1);       
  2. curl_setopt($ch, CURLOPT_NOBODY, 1);      

或者只獲取body:

 
 
 
  1. curl_setopt($ch, CURLOPT_HEADER, 0);   
    // make sure we get the body     
  2. curl_setopt($ch, CURLOPT_NOBODY, 0);     

4. 訪問虛擬主機(jī),需設(shè)置Host

 
 
 
  1. $header[]= 'Host: '.$host;   

5. 使用post, put, delete等REStful方式訪問url

 
 
 
  1. post:   
  2.  
  3.   curl_setopt($ch, CURLOPT_POST, 1 );   
  4.  
  5. put, delete:   
  6.  
  7.   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");  
    //或者PUT,需要服務(wù)器支持這些方法。  

6. php curl保存下載內(nèi)容為文件

 
 
 
  1. curl_setopt($ch, CURLOPT_FILE, $fp);  

網(wǎng)頁(yè)名稱:PHP語(yǔ)言中phpcurl的幾種應(yīng)用方式
標(biāo)題來(lái)源:http://www.5511xx.com/article/dphpedo.html