Developer manual
- ^ References
- ^ Class utilities
- jApp: directories of the application
- jFilter: verifying and filtering datas
- jDateTime: dates and times
- jHttp: http requests
- jMailer: sending mails
- jWiki: generating contents from wiki contents
- jSession: managing sessions
- jMessage: short messages between actions
- jFile: file processing
- jPref: using application preferences
Jelix 1.6.34
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) ....
}