Updated library to use cURL instead of file_get_contents

This commit is contained in:
Evan Seguin
2012-07-19 10:50:31 -07:00
parent 04f9c98ad9
commit 1c503f13ff
3 changed files with 24 additions and 17 deletions

View File

@@ -63,24 +63,31 @@ class HttpClient {
private static function execRequest($httpMethod, $url, $parameters, $publicKey, $privateKey) {
$data = null;
if ($httpMethod != HttpMethod::GET) {
$url = self::removeQueryString($url);
//$url = self::removeQueryString($url);
$data = http_build_query($parameters);
}
$headers = AuthUtil::generateAuthenticationHeader($publicKey, $privateKey);
$headers .= UrlUtils::generateClientHeaders();
$opts = array('http' =>
array(
'ignore_errors' => true,
'method' => $httpMethod,
'content' => $data,
'header' => $headers
)
);
//$headers = array();
$headers = array(
);
$headers[] = AuthUtil::generateAuthenticationHeader($publicKey, $privateKey);
$headers[] = UrlUtils::generateClientHeaders();
$context = stream_context_create($opts);
$response = @file_get_contents($url, false, $context);
$ch = curl_init ();
// prepare the request
//curl_setopt($ch, CURLOPT_USERPWD, "username:password"); for basic auth
curl_setopt ($ch, CURLOPT_URL , $url);
if ($httpMethod != HttpMethod::GET) {
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
//curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
}
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}