php如何发起POST DELETE GET POST 请求
2016-02-23 17:10
633 查看
get:是用来取得数据。其要传递过的信息是拼在url后面,因为其功能使然,有长度的限制
post:是用来上传数据。要上传的数据放在request的head里。没有长度限制。主要是用于增加操作
put:也是用来上传数据。但是一般是用在具体的资源上。主要用于修改操作
delete:用来删除某一具体的资源上
发起POST DELETE GET POST 请求通用类
<?php class commonFunction{ function callInterfaceCommon($URL,$type,$params,$headers){ $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $URL); //发贴地址 if($headers!=""){ curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers); }else { curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-type: text/json')); } curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); switch ($type){ case "GET" : curl_setopt($ch, CURLOPT_HTTPGET, true);break; case "POST": curl_setopt($ch, CURLOPT_POST,true); curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break; case "PUT" : curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break; case "DELETE":curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($ch, CURLOPT_POSTFIELDS,$params);break; } $file_contents = curl_exec($ch);//获得返回值 return $file_contents; curl_close($ch); } } ?>
$params="{user:\"admin\",pwd:\"admin\"}"; $headers=array('Content-type: text/json',"id: $ID","key:$Key"); $url=$GLOBALS["serviceUrl"]."/user"; $strResult= spClass("commonFunction")->callInterfaceCommon($url,"PUT",$params,$headers);
相关文章推荐
- PHP curl 实现RESTful PUT DELETE 实例
- PHP之设计模式(工厂、单例)
- Ubuntu下启动pptp失败问题
- ubuntu 14.04 部署vsftpd
- php中Mail_mimeDecode无法读取foxmail等eml文件正文问题
- editplus快捷键大全
- phpcms /api/phpsso.php SQL Injection Vul
- 实现RTP协议的H.264视频传输系统
- Thinkphp中的内置标签用法
- PHP设计模式-单例模式
- fsl 环境搭建与tftp nfs samba配置 分包压缩
- php判断数组元素是否存在某个字符串的方法
- yii2.0 分页(二)
- GD库,是php处理图形的扩展库
- php常用函数(不定时更新)
- PHP - urlencode和rawurlencode的区别
- PHP数据类型转换
- php 信息采集代码
- PHP---json
- PHP框架实现数据库连贯查询的思路解析