1

I am developing an UI for a REST repository using PHP and the PEAR HTTP REQUEST package (http://pear.php.net/package/HTTP_Request/). I created a HTTP GET request and it delivers the requested rdf/xml file as expected. But I want to extend this request and I can't get this working. The repository allows sending zip files which are attached to an id. So I have to call the same URL which delivers the rdf/xml data, but I have to change the HTTP GET header from xml to accept: application/zip, before executing my request. This should deliver the zip instead of the rdf/xml file.

$req =& new HTTP_Request();
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->setURL($url);
$req->clearPostData();
if (!PEAR::isError($req->sendRequest())) {
     $response2 = $req->getResponseBody();
} else {
     $response2 = "";
}

echo $response2;

Does anyone know how to modify the GET call to get this done? I really need help!

Furthermore I want to create a HTTP PUT request which uses multipart/form-data. Does anyone know how to make this?

Please help me! Thanks!

2 Answers 2

2

For your first question, you can set the Accept field of your GET request header by:

$req->addHeader('Accept', 'application/zip');
# assuming that this will trigger the server to respond with the zip and not xml

Question number 2:

# Set method to PUT
$req->setMethod(HTTP_REQUEST_METHOD_PUT);

# Attach file to request
$req->addFile('file_upload_field', '/path/to/file.ext', 'application/zip');

Read up more on file uploads using HTTP_Request.

Sign up to request clarification or add additional context in comments.

3 Comments

@ PUT: Can I add with addFile several files, beacuse I have to submit an rdf/xml file to the REST repository optinally an zip archive?
@Matt if the server allows you to send multiple files in one request then you can. Just note that there is an upload limit, or max total file size for uploads. And it would be great if you mark this as an accepted answer:)
Okay. The GET issue is fixed, but I still have to work on the PUT. THANKS!!
0

To modify the request headers, take a look at the addHeader() method of the HTTP_Request object: http://pear.php.net/manual/en/package.http.http-request.headers.php

To change the method, use the setMethod(): http://pear.php.net/package/HTTP_Request/docs/latest/HTTP_Request/HTTP_Request.html#methodsetMethod

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.