Skip to content

Instantly share code, notes, and snippets.

@sidchilling
Created November 30, 2012 19:06
Show Gist options
  • Save sidchilling/4177798 to your computer and use it in GitHub Desktop.
Save sidchilling/4177798 to your computer and use it in GitHub Desktop.
CURL method to make POST request
<?php
$url = 'http://localhost/tests/test_post'; # URL for the POST request
$request = curl_init($url);
$post_options = array(
CURLOPT_POST => 1, # signifies it is a POST request
CURLOPT_POSTFIELDS => $data, # $data is the data that you want to POST
CURLOPT_RETURNTRANSFER => true # required if you want to capture the response data as a string instead of just printing to the console
);
curl_setopt_array($request, $post_options);
$response = curl_exec($request);
curl_close($request);
if ($response === false) {
print "Could not make successful request\n";
} else {
$response = json_decode($response);
# $response is the response from the web-service
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment