首頁  >  文章  >  後端開發  >  portfree production program php的curl實作get與post的程式碼

portfree production program php的curl實作get與post的程式碼

WBOY
WBOY原創
2016-07-29 08:38:381021瀏覽

curl 支援SSL憑證、HTTP POST、HTTP PUT 、FTP 上傳,kerberos、基於HTT格式的上傳、代理、cookie、用戶+口令證明、文件傳送恢復、http代理通道就最常用的來說,是基於http的get和post方法。
程式碼實作:
1、http的get實作

複製程式碼 程式碼如下:


$ch = curl_init("http://www.jb51.net/") ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; $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 = 'http://www.jb51.net/get-post.php' ;
$fields = array(
'lname'=>urlencode($last_name) ,
'fname'=>urlencode($first_name) ,
'title'=>urlencode($title) ,
'company'=>urlencode($ institution) ,
'age'=>urlencode($age) ,
'email'=>urlencode($email) ,
'phone'=>urlencode($phone)
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&' ; }
rtrim($fields_string ,'&') ;
//open connection
$ch = curl_init() ;
//set the url, number of POST vars, POST data
curl_setopt($ch , CURLOPT_URL,$url) ;
curl_setopt($ch, CURLOPT_POST,count($fields)) ;
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string) ;
= curl_exec($ch) ;
//close connection
curl_close($ch) ;


以上就介紹了portfree production program php的curl實作get和post的程式碼,包含了portfree production program方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn