Jelix 1.2.13
Section: jHttp: http requests
« jDateTime: dates and times | ^ Class utilities | jMailer: sending mails » |
Switch to language: FR
jHttp is a class defining an API to make http request targeting external urls. It can be useful to call web services, for example. It inherits from netHttp of clearbricks package. netHttp is included in default Jelix packages.
jHttp supports redirection, cookies, SSL, user agent string...
A simple example
// send a GET request
$pageweb = jHttp::quickGet('http://example.local/index.html');
// send a POST request
$data = array('foo'=>'bar');
$pageweb = jHttp::quickPost('http://example.local/submit.php', $data);
// more complex
$http = new jHttp('http://example.local');
$http->setCookies(array('hello'=>'world');
if($http->get('index.html')) {
$pageweb = $http->getContent();
}
else {
$status= $http->getStatus();
if($status == 404) ....
}
// POST request
$data = array('foo'=>'bar');
if($http->post('submit.php', $data)) {
$pageweb = $http->getContent();
}
else {
$status= $http->getStatus();
if($status == 404) ....
}