国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

PHP的curl實現get和post

瀏覽:2日期:2024-02-23 08:53:46

類似于dreamhost這類主機服務商,是顯示fopen的使用的。使用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('http://www.devdao.com/') ;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 postextract($_POST) ; //set POST variables$url = 'http://www.webjx.com/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 POSTforeach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&' ; }rtrim($fields_string ,'&') ;//open connection$ch = curl_init() ;//set the url, number of POST vars, POST datacurl_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) ;//close connectioncurl_close($ch) ;

標簽: PHP
主站蜘蛛池模板: 繁峙县| 大埔县| 临安市| 时尚| 南平市| 磐石市| 焦作市| 康保县| 溆浦县| 湛江市| 慈利县| 合肥市| 工布江达县| 太保市| 屏山县| 兖州市| 内黄县| 富川| 浦江县| 屯昌县| 武平县| 江山市| 宝坻区| 滨州市| 上思县| 高要市| 桑植县| 泉州市| 黄石市| 噶尔县| 怀柔区| 秦安县| 册亨县| 石狮市| 从江县| 崇礼县| 本溪市| 吴堡县| 岱山县| 昌图县| 南岸区|