Skip to content

Instantly share code, notes, and snippets.

@peerax
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peerax/cc9deb1a0ecff78e14e3 to your computer and use it in GitHub Desktop.
Save peerax/cc9deb1a0ecff78e14e3 to your computer and use it in GitHub Desktop.
$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);
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;
}
<?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