首页 »PHP教程 » phpcurlpost:php的curl实现get和post »正文
phpcurlpost:php的curl实现get和post
来源: 发布时间:星期一, 2009年1月12日 浏览:81次 评论:0
类似于dreamhost这类主机服务商 ![](/icons/69271dou.gif) 是显示fopen ![](/icons/69271de.gif) 使用 ![](/icons/69271de.gif) ![](/icons/69271dou2.gif) 使用php ![](/icons/69271de.gif) curl可以实现支持FTP、FTPS、HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE和LDAP ![](/icons/69271dou2.gif) curl 支持SSL证书、HTTP POST、HTTP PUT 、FTP 上传 ![](/icons/69271dou.gif) kerberos、基于HTT格式 ![](/icons/69271de.gif) 上传、代理、cookie、用户+口令证明、文件传送恢复、http代理通道就最常用 ![](/icons/69271de.gif) 来说 ![](/icons/69271dou.gif) 是基于http ![](/icons/69271de.gif) get和post思路方法 ![](/icons/69271dou2.gif) 代码实现: 1、http ![](/icons/69271de.gif) get实现 $ch = curl_init("http://tech.ddvip.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、http ![](/icons/69271de.gif) post实现 //extract data from the post extract($_POST) ; // POST variables $url = 'http://tech.ddvip.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) ;
相关文章
读者评论
发表评论
|
|