Skip to content

Instantly share code, notes, and snippets.

@sidchilling
Created November 30, 2012 20:01
Show Gist options
  • Select an option

  • Save sidchilling/4178176 to your computer and use it in GitHub Desktop.

Select an option

Save sidchilling/4178176 to your computer and use it in GitHub Desktop.
HttpRequest for POST with file
<?php
$file_path = '/home/siddharthsaha/Desktop/production.html';
$data = array(
'owner' => 'siddharth saha'
);
$request = new HttpRequest($url, HttpRequest::METH_POST);
$request->addPostFields($data); # Adding the data with the POST method
$request->addPostFile('test_file', $file_path); # The file has to be posted with a separate method.
$request->send();
if ($request->getResponseCode() == 200) {
$response = json_decode($request->getResponseBody());
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment