PUT in PEAR HTTP_Request
|
|
How to use PUT for uploading the file. Please let me know th API or post an example. |
|
|
Here is the doc to do this: http://pear.php.net/manual/en/package.http.http-request.file-upload.php |
|
|
Not POST, but by http PUT method. in your documentation, it says, it can support PUT. How do I use it? |
|
|
We don’t support upload via PUT method, only post multipart form. |
|
|
For updating the title via PUT, can we do that? A simple example will be very useful. Appreciate your help. |
|
|
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 = "";
}
|
|
|
I did put in setHeader for contentLength. It does not work. |
|
|
Hi Bruno, Is there any PUT request that works? I tried all the API and it is not working. Thanks |
|
|
PUT request is only for update purpose. What is your code and what are you trying to do? |
|
|
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. |
|
|
It means that there is not sent data. What is your code exactly? |
|
|
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 |
|
|
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. |
|
|
It did not work either. I am using php 4.4.7 does it matter? Thanks |
|
|
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. |
|
|
It works !!! Thanks and appreciate your help ! |