Created
November 30, 2012 19:06
-
-
Save sidchilling/4177798 to your computer and use it in GitHub Desktop.
CURL method to make POST request
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
<?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