Last active
August 29, 2015 14:16
-
-
Save peerax/cc9deb1a0ecff78e14e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$curl = curl_init(); | |
// Set some options - we are passing in a useragent too here | |
curl_setopt_array($curl, array( | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_URL => 'http://testcURL.com/?item1=value&item2=value2', | |
CURLOPT_USERAGENT => 'Codular Sample cURL Request' | |
)); | |
// Send the request & save response to $resp | |
$resp = curl_exec($curl); | |
// Close request to clear up some resources | |
curl_close($curl); |
This file contains hidden or 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
function processCurlJsonrequest($URL, $fieldString) { //Initiate cURL request and send back the result | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | |
curl_setopt($ch, CURLOPT_URL, $URL); | |
curl_setopt($ch, CURLOPT_USERAGENT, $this->_agent); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); | |
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_cookie_file_path); | |
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_cookie_file_path); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); | |
curl_setopt($ch, CURLOPT_VERBOSE, TRUE); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("myJsonData" => "test"))); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
$resulta = curl_exec($ch); | |
if (curl_errno($ch)) { | |
print curl_error($ch); | |
} else { | |
curl_close($ch); | |
} | |
return $resulta; | |
} |
This file contains hidden or 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 | |
$curl = curl_init(); | |
// Set some options - we are passing in a useragent too here | |
curl_setopt_array($curl, array( | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_URL => 'http://shop.surinrobot.com/web_service/shop_login.php', | |
CURLOPT_USERAGENT => 'Mozole', | |
CURLOPT_POST => 1, | |
CURLOPT_POSTFIELDS => array( | |
'user_username' => 'demo', | |
'user_password' => 'surinrobot' | |
) | |
)); | |
// Send the request & save response to $resp | |
$resp = curl_exec($curl); | |
print_r($resp); | |
// Close request to clear up some resources | |
curl_close($curl); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment