Client
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 as long as the
$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);
Service side
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> ';
Client
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 as long as the
$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);
Service side
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 implements restful PUT DELETE instance