PHP curl POST 獲取返回整個頁面值

2021-06-16 05:00:04 字數 1349 閱讀 2609

使用php的curl可以實現支援ftp、ftps、http htpps scp sftp tftp telnet dict file和ldap。curl 支援ssl證書、http post、http put 、ftp 上傳,kerberos、基於htt格式的上傳、**、cookie、使用者+口令證明、檔案傳送恢復、http**通道就最常用的來說,是基於http的get和post方法。

**實現:

1、http的get實現

$ch = curl_init("

/") ;

curl_setopt($ch, curlopt_returntransfer, true) ;

curl_setopt($ch, curlopt_binarytransfer, true) ;

$output = curl_exec($ch) ;

$fh = fopen("out.html", 'w') ;

fwrite($fh, $output) ;

fclose($fh) ;

2、http的post實現

//extract data from the post

extract($_post) ; 

//set post variables

$url = '' ;

$fields = array(

'bill_id' => urlencode('201002420268'),

'hname' => urlencode('hvalue')

); 

//url-ify the data for the post

$fields_string ='';

foreach($fields as $key=>$value)

rtrim($fields_string ,'&') ;

//open connection

$ch = curl_init() ;

//set the url, number of post vars, post data

$url =  $url.rtrim($fields_string ,'&') ;

curl_setopt($ch, curlopt_url,$url) ;

curl_setopt($ch, curlopt_post,count($fields)) ;

curl_setopt($ch, curlopt_postfields,$fields_string) ;

//execute post

$result = curl_exec($ch) ;

print_r($result);

//close connection

curl_close($ch) ;

PHP curl POST 請求的問題

參考 php用curl進行 post請求的大致過程是 url postdata k1 v1 k2 v2 ch curl init url curl setopt ch,curlopt post,1 curl setopt ch,curlopt postfields,postdata curl set...

POST獲取html返回405

爬蟲之httppost 返回狀態碼 405 問題 發現httppost請求目標 會出現 405 狀態碼,原因為 apache iis nginx 等絕大多數 web伺服器,都不允許靜態檔案響應 post請求 將post請求換成 get請求即可 post傳遞引數用 listnvps newarrayl...

反射獲取方法返回結果

在我們開發中,有乙個統一的介面,然後我們幾個開發的都實現這個介面 通過反射獲得方法返回結果 拋異常我就省略了 bean 介面 methodname 方法名 params 引數集合 paramclass 引數的class result 方法返回值 public static object execut...