How to perform an external request in Kohana 3? How to perform an external request in Kohana 3? curl curl

How to perform an external request in Kohana 3?


I don't know if this was initially written when the OP was using Kohana 3.0, but the major release Kohana 3.1 has made this significantly easier to do. The Remote::get() is deprecated (and wasn't that good to begin with). To accomplish this in Kohana 3.1 is a simple matter, and you pretty much had it:

$url = 'http://www.example.com';$request = Request::factory($url)    ->method('POST')    ->post('key', 'value');$response = $request->execute();echo $response->body();

I moved some stuff around to take advantage of the succinctness of the chaining syntax. With the response, you can check the response code as well. For more information read the 3.1 API docs for Request and Request_Client_External (which handles these external i.e. not within-app requests.


Just read this at the bottom

The request class used in this example is currently available as part of a Kohana Core development branch within my personal github account, which can be obtained from http://github.com/samsoir/core. If using the official Kohana PHP 3.0 download, a custom extension of the request class is required.

Also see this discussion.


The Request object is used to request pages within your application. You can't use it for external URLs. Oh, and you don't have to use curl, you can make it easier by doing this:

$page = file_get_contents('http://google.com');