Skip to content

Instantly share code, notes, and snippets.

@mbabker
Created June 9, 2012 21:00
Show Gist options
  • Save mbabker/2902581 to your computer and use it in GitHub Desktop.
Save mbabker/2902581 to your computer and use it in GitHub Desktop.
Example JHttp Use
// 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