portfreeproductionprogramphp的curl实现get和post的代码

portfreeproductionprogramphp的curl实现get和post的代码

内容导读

收集整理的这篇技术教程文章主要介绍了portfreeproductionprogramphp的curl实现get和post的代码,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1396字,纯文字阅读大概需要2分钟

内容图文

curl 支持SSL证书、HTTP POST、HTTP PUT 、FTP 上传,kerberos、基于HTT格式的上传、代理、cookie、用户+口令证明、文件传送恢复、http代理通道就最常用的来说,是基于http的get和post方法。
代码实现:
1、http的get实现

代码如下:


$ch = curl_init("http://www.gxlcms.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 post
extract($_POST) ;
//set POST variables
$url = 'http://www.gxlcms.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 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) ;
//execute post
$result = curl_exec($ch) ;
//close connection
curl_close($ch) ;

以上就介绍了portfree production program php的curl实现get和post的代码,包括了portfree production program方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

内容总结

以上是为您收集整理的portfreeproductionprogramphp的curl实现get和post的代码全部内容,希望文章能够帮你解决portfreeproductionprogramphp的curl实现get和post的代码所遇到的程序开发问题。 如果觉得技术教程内容还不错,欢迎将网站推荐给程序员好友。

内容备注

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。



联系我们

在线咨询:点击这里给我发消息

邮件:w420220301@qq.com