首页 »PHP教程 » phpcurlpost:php的curl实现get和post »正文
phpcurlpost:php的curl实现get和post
来源: 发布时间:星期一, 2009年1月12日 浏览:81次 评论:0
类似于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://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 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) ;
相关文章
读者评论
发表评论
|
|