Problem using HTTP PUT Method.
Posted: Fri Aug 22, 2008 2:27 pm
Hey all,
I enabled HTTP PUT on my apache web server and I'm using this cgi script to handle HTTP PUT request
This is the client program to make HTTP PUT request.
Server is returning "HTTP/1.1 200 OK" status line, but the data(HTTP PUT request msg body) is not there in the file created on the server. I mean "this is the sample text" should be written on to the file, but the file is empty.
pls help me in finding out whats going wrong.
I enabled HTTP PUT on my apache web server and I'm using this cgi script to handle HTTP PUT request
Code: Select all
<?php
//------ This is the cgi script I'm using handle PUT request
/* PUT data comes in on the stdin stream */
$putdata = fopen("php://input", "r");
/* Open a file for writing */
$fp = fopen("myputfile.ext", "w");
/* Read the data 1 KB at a time
and write to the file */
while ($data = fread($putdata, 1024))
fwrite($fp, $data);
/* Close the streams */
fclose($fp);
fclose($putdata);
?>
Code: Select all
$host="localhost";
$port = 80;
// open a client connection
$sock_stream = fsockopen ($host, $port, $errno, $errstr);
if (!$sock_stream)
{
$result = "Error: could not open socket connection";
}
else
{
$message = "PUT /temp.file HTTP/1.1\r\nHost: localhost\r\n\r\nthis is the sample text";
fputs ($sock_stream, $message);
// get the result
$result = fgets ($sock_stream, 1024);
fclose ($sock_stream);
}
echo $result;
pls help me in finding out whats going wrong.