专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » phpcurlpost:PHP的curl实现get和post »正文

phpcurlpost:PHP的curl实现get和post

来源: 发布时间:星期二, 2008年12月30日 浏览:100次 评论:0
类似于dreamhost这类主机服务商是显示fopen使用使用phpcurl可以实现支持FTP、FTPS、HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE和LDAPcurl 支持SSL证书、HTTP POST、HTTP PUT 、FTP 上传kerberos、基于HTT格式上传、代理、cookie、用户+口令证明、文件传送恢复、http代理通道就最常用来说是基于httpget和post思路方法

代码实现:

1、httpget实现

$ch = curl_init("http://www.webjx.com/") ;
curl_opt($ch, CURLOPT_RETURNTRANSFER, true) ;
curl_opt($ch, CURLOPT_BINARYTRANSFER, true) ;
$output = curl_exec($ch) ;
$fh = fopen("out.html", 'w') ;
fwrite($fh, $output) ;
fclose($fh) ;

2、httppost实现

//extract data from the post
extract($_POST) ; 
// POST variables
$url = 'http://www.webjx.com/get-post.php' ;
$fields = .gif' />(
                        'lname'=>urlencode($last_name) ,
                        'fname'=>urlencode($first_name) ,
                        'title'=>urlencode($title) ,
                        'company'=>urlencode($institution) ,
                        'age'=>urlencode($age) ,
                        'email'=>urlencode($email) ,
                        'phone'=>urlencode($phone)
                ); 
//url-y the data for the POST
foreach($fields as $key=>$value) { $fields_ .= $key.'='.$value.'&' ; }
rtrim($fields_ ,'&') ;
//open connection
$ch = curl_init ;
// the url, number of POST vars, POST data
curl_opt($ch, CURLOPT_URL,$url) ;
curl_opt($ch, CURLOPT_POST,count($fields)) ;
curl_opt($ch, CURLOPT_POSTFIELDS,$fields_) ;
//execute post
$result = curl_exec($ch) ;
//close connection
curl_close($ch) ;


1

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: