Created
June 9, 2012 21:00
-
-
Save mbabker/2902581 to your computer and use it in GitHub Desktop.
Example JHttp Use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set up our JRegistry object for the HTTP connector | |
$options = new JRegistry; | |
// Set the user agent | |
$options->set('userAgent', 'JInstallation/3.0'); | |
// Use a 120 second timeout | |
$options->set('timeout', 120); | |
// Instantiate our JHttp object | |
$http = new JHttp($options); | |
// Build our data array | |
$data = array( | |
'data1' => 'foo', | |
'data2' => 'bar', | |
'data3' => 'Login' | |
); | |
// JSON encode the data | |
$data = json_encode($data); | |
// Post the data | |
$response = $http->post('http://localhost:8888/curl/get-data.php', $data); | |
// Check if we received the proper response code | |
if ($response->code != 201) | |
{ | |
// Error condition | |
} | |
// From here, build the response object for the installer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment