PHP curl 实现RESTful PUT DELETE 实例
PHP curl 实现RESTful PUT DELETE 实例
客户端
client.php
<?php
//PUT
$curl_handle = curl_init ();
// Set default options.
curl_setopt ( $curl_handle, CURLOPT_URL, 'http://my.focus.cn/test/socket.php');
curl_setopt ( $curl_handle, CURLOPT_FILETIME, true );
curl_setopt ( $curl_handle, CURLOPT_FRESH_CONNECT, false );
curl_setopt ( $curl_handle, CURLOPT_HEADER, true );
curl_setopt ( $curl_handle, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl_handle, CURLOPT_TIMEOUT, 5184000 );
curl_setopt ( $curl_handle, CURLOPT_CONNECTTIMEOUT, 120 );
curl_setopt ( $curl_handle, CURLOPT_NOSIGNAL, true );
curl_setopt ( $curl_handle, CURLOPT_HEADER, true );
curl_setopt ( $curl_handle, CURLOPT_CUSTOMREQUEST, 'PUT' );
$aHeader[] = "Content-Type:text/xml;charset=UTF-8";
$aHeader[] = "x-bs-ad:private";
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $aHeader);
$file = 'client.php';
$file_size = filesize($file);
$h = fopen($file,'r');
curl_setopt ( $curl_handle, CURLOPT_INFILESIZE, $file_size);
curl_setopt ( $curl_handle, CURLOPT_INFILE, $h);
curl_setopt ( $curl_handle, CURLOPT_UPLOAD, true );
$ret = curl_exec ( $curl_handle );
print_r($ret);
?>
DELETE 只要将
$curl_handle = curl_init ();
// Set default options.
curl_setopt ( $curl_handle, CURLOPT_URL, 'http://my.focus.cn/test/socket.php?file=socket.txt');
curl_setopt ( $curl_handle, CURLOPT_FILETIME, true );
curl_setopt ( $curl_handle, CURLOPT_FRESH_CONNECT, false );
curl_setopt ( $curl_handle, CURLOPT_HEADER, true );
curl_setopt ( $curl_handle, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl_handle, CURLOPT_TIMEOUT, 5184000 );
curl_setopt ( $curl_handle, CURLOPT_CONNECTTIMEOUT, 120 );
curl_setopt ( $curl_handle, CURLOPT_NOSIGNAL, true );
curl_setopt ( $curl_handle, CURLOPT_CUSTOMREQUEST, 'DELETE' );
$ret = curl_exec ( $curl_handle );
服务端
server.php
<?php
$raw_post_data = file_get_contents('php://input', 'r');
$method = $_SERVER['REQUEST_METHOD'];
if('PUT' == $method)
{
$headers = apache_request_headers();
file_put_contents('socket.txt',$raw_post_data.print_r($headers,true));
}
else if('DELETE'==$method)
{
unlink($_GET['file']);
}
echo '<?xml version="1.0" encoding="UTF-8"?><RET>OK</RET>';
PHP curl 实现RESTful PUT DELETE 实例的更多相关文章
- 【转】php curl 伪造IP来源的实例代码
curl发出请求的文件fake_ip.php: 代码 复制代码 代码如下: <?php $ch = curl_init(); $url = "http://localhost/targ ...
- php curl 伪造IP来源的实例代码
来源:http://www.jb51.net/article/31694.htm curl 它不但可以模仿用户登录,还可以模仿用户IP地址哦,为伪造IP来源,本实例仅供参考哦 //伪造ip ; $i ...
- PHP中使用CURL模拟文件上传实例
调用实例: 该方法将本地的E盘文件test.doc上传到接口服务器上的 uploadFile方法中,uploadFile会对上传的文件做进一步处理. 若你想自己对上传的文件做操作,将接口uploadF ...
- 比 file_get_contents() 更优的 cURL 详解(附实例)
PHP 可以使用 file_get_content() 函数抓取网页内容,但却无法进行更复杂的处理,譬如文件的上传或下载. Cookie 操作等等.而 cURL 提供了这些功能. 一.cURL简介 在 ...
- SpringMVC(三)Restful风格及实例、参数的转换
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 一.Restful风格 1.Restful风格的介绍 Restful 一种软件架构风格.设计风格,而不是 ...
- cURL的几个经典实例
1.cURL请求的基本步骤: (1)初始化 (2)设置选项,包括URL (3)执行并获取HTML文档内容 (4)释放cURL句柄 <?php //1.初始化 $ch = curl_init(); ...
- RESTful WebService 入门实例
/* 新建MavenProject,使用以下代码,创建类和POM文件.使用命令行切换到Project根目录,运行mvn package(或者,选中pom.xml 文件右键单击 > run a ...
- Spring4 MVC RESTFul WebServices CRUD实例+RestTemplate
简单介绍REST REST 表示状态传输.这是一个体系结构样式,可用于设计网络服务,可以被各种客户端消耗.核心思想是,不使用如CORBA,RPC或SOAP复杂的机制在机器之间进行连接,简单的 HTTP ...
- RESTFul Client入门实例
client.html文件内容为: <!DOCTYPE html> <html> <head> <title>RESTFul Client test p ...
随机推荐
- 阿里云推荐码 hut29f
阿里云 推荐码 hut29f,适用于新手首次购买.
- [nodejs] Error: unable to verify the first certificate
Error: unable to verify the first certificate Solution npm config set registry http://registry.npmjs ...
- C++预定义字符函数
利用 get 成员函数可读取文件中的一切字符,包括空白字符.文件结尾.用 >> 读取文件,会自动忽略空白字符(空格.换行符.制表符) C++ 预定义的字符函数(均在 cctype 库中定义 ...
- [liusy.api-SMJ]-MAVEN archetype 创建项目
•选择或创建工作空间 Select a workspace –File – Switch Workspace - other
- ldap配置记录
记录一下最近研究ldap+nfs的情况 ldap这个东西上次研究nis的时候就有人说那是上个世纪的老东西了,不应该继续使用.虽然意识到如此但时间不够还是使用了nis,这次乘着重做就干脆切换到ldap, ...
- table 边框显示
.td{border:solid #add9c0; border-width:0px 1px 1px 0px;}.table{border:solid #add9c0; border-width:1p ...
- http 协议集合,超级简单
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Web; ...
- 【转载】Windows下VSCode编译调试c/c++
懒得自己配置或自己配置出现不明问题的朋友可以点这里: [VSCode]Windows下VSCode便携式c/c++环境 http://blog.csdn.net/c_duoduo/article/de ...
- set、def、lambda、内置函数、文件操作
set : 无序,不重复,可以嵌套 .add (添加元素) .update(接收可迭代对象)---等于批量 添加 .diffrents()两个集合不同差 .sysmmetric difference( ...
- scoi 2008 && bzoj 1076 奖励关
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3223 思路:15?好,状压,OK. 这是转移方程 if((s[k]&j)==s[k] ...