PHP curl get post通用类
2024-08-25 23:12:26
<?php
/**
* @author:xiaojiang
* curl 通用方法 。。get /post 传送数据
*/
class process{ const GET = 0;
const POST = 1;
public $url;
public $ch = null;
private $type = 1; public function __construct( $url , $type = self::POST){
$this->url = $url;
$this->ch = curl_init();
$this->type = $type;
} //设置发送方式 0 get 1 post
public function setType( $type ){
$this->tyep = $type;
}
//post 方式传递数据
public function send( $param ){
if( self::POST == $this->type)
return $this->posts( $param );
else
return $this->gets( $param );
} public function posts( $post_data ){ curl_setopt( $this->ch, CURLOPT_URL, $this->url );
curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $this->ch, CURLOPT_HEADER, 0 );
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec( $this->ch );
return $output;
} public function gets( $get_data ){ $url = $this->url.'?'.http_build_query($get_data);
curl_setopt( $this->ch, CURLOPT_URL, $url );
curl_setopt( $this->ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $this->ch, CURLOPT_HEADER, 0 );
$output = curl_exec( $this->ch );
return $output; } }
最新文章
- setTimeout使用闭包功能,实现定时打印数值
- FJOI省队集训 chessboard
- Android应用中使用及实现系统“分享”接口
- 解决安装office2013时提示已安装相同版本的office
- php文件上传之多文件上传
- ODTwithODAC认识与安装图解
- maven项目编译漏掉src/main/java下的xml配置文件
- EasyUI_Datagrid学习总结
- Jquery 操作xml 文档的方法
- TextView设置动态改变颜色
- 最小生成树之算法记录【prime算法+Kruskal算法】【模板】
- AngularJS自定义表单验证器
- C#9 结构体 员工信息 学生成绩
- VICC国际标准ISO15693下载
- Java关键字transient和volatile小结(转)
- iOS 给UITextView加一个placeholder
- 如何用while循环 输出一个九九乘法表
- (Matlab)GPU计算所需的配置
- 理解Go Interface
- Spring Boot的事务处理