PUT in PEAR HTTP_Request

Subscribe to PUT in PEAR HTTP_Request 16 posts, 2 voices

 
Avatar srallabandi 9 posts

How to use PUT for uploading the file. Please let me know th API or post an example.

 
Avatar Bruno Celeste 375 posts

Here is the doc to do this: http://pear.php.net/manual/en/package.http.http-request.file-upload.php

 
Avatar srallabandi 9 posts

Not POST, but by http PUT method. in your documentation, it says, it can support PUT. How do I use it?

 
Avatar Bruno Celeste 375 posts

We don’t support upload via PUT method, only post multipart form.

 
Avatar srallabandi 9 posts

For updating the title via PUT, can we do that? A simple example will be very useful. Appreciate your help.

 
Avatar Bruno Celeste 375 posts

Yes I think it could work:

require_once "HTTP/Request.php";

$req =& new HTTP_Request("http://heywatch.com/encoded_video/ID.xml");
$req->setMethod(HTTP_REQUEST_METHOD_PUT);
$req->addPostData("title", "my new title");
if (!PEAR::isError($req->sendRequest())) {
     $response1 = $req->getResponseBody();
} else {
     $response1 = "";
}
 
Avatar srallabandi 9 posts

I did put in setHeader for contentLength. It does not work.

 
Avatar srallabandi 9 posts

Hi Bruno,

Is there any PUT request that works? I tried all the API and it is not working.

Thanks

 
Avatar Bruno Celeste 375 posts

PUT request is only for update purpose. What is your code and what are you trying to do?

 
Avatar srallabandi 9 posts

I understand that and thats what I am trying to do. What I am trying to do is to update the title of an existing encoded video or an uploaded video. When I used the example above, it threw an error “411 Content length required”. When I added addHeader(“Content-Length”, 10), the title does not update, just no return.

 
Avatar Bruno Celeste 375 posts

It means that there is not sent data. What is your code exactly?

 
Avatar srallabandi 9 posts

Let us take your example. require_once “HTTP/Request.php”;

$req =& new HTTP_Request(“http://heywatch.com/encoded_video/ID.xml”); $req->setMethod(HTTP_REQUEST_METHOD_PUT); $req->addPostData(“title”, “my new title”); $req->addHeader(“Content-Length”,12);

if (!PEAR::isError($req->sendRequest())) { $response1 = $req->getResponseBody(); } else { $response1 = ””; }

Can you please test this and let me know if it works? There is no response and data is not updated.

Thanks

 
Avatar Bruno Celeste 375 posts

Here is the good code:

<?php
require_once "HTTP/Request.php";

$req =& new HTTP_Request("http://heywatch.com/video/ID.xml");
$req->setBasicAuth("johndoe", "foo");
$req->setMethod(HTTP_REQUEST_METHOD_PUT);
$req->addQueryString("title", "My new title");

if (!PEAR::isError($req->sendRequest())) {
    echo $req->getResponseBody();
}
?>

It’s addQueryString, not addPostData as I though.

 
Avatar srallabandi 9 posts

It did not work either. I am using php 4.4.7 does it matter?

Thanks

 
Avatar Bruno Celeste 375 posts

I think PEAR HTTP request is a little bit buggy with PUT request.

<?php
require_once "HTTP/Request.php";

$req =& new HTTP_Request("http://heywatch.com/video/ID.xml");
$req->setBasicAuth("johndoe", "foo");
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addPostData("title", "My new title");
$req->addPostData("_method", "put");

if (!PEAR::isError($req->sendRequest())) {
    echo $req->getResponseBody();
}
?>

This is tested and works perfectly this time.

 
Avatar srallabandi 9 posts

It works !!! Thanks and appreciate your help !