Source for file Curl.php
Documentation is available at Curl.php
* Copyright (c) 2009, RealDolmen
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of RealDolmen nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @package Microsoft_Http
* @version $Id: Curl.php 22249 2009-06-18 09:49:55Z unknown $
* @copyright Copyright (c) 2009, RealDolmen (http://www.realdolmen.com)
* @license http://phpazure.codeplex.com/license
* @see Microsoft_Http_Transport_Exception
require_once 'Microsoft/Http/Transport/Exception.php';
* @see Microsoft_Http_Transport
require_once 'Microsoft/Http/Transport.php';
* @see Microsoft_Http_Response
require_once 'Microsoft/Http/Response.php';
* @package Microsoft_Http
* @copyright Copyright (c) 2009, RealDolmen (http://www.realdolmen.com)
* @license http://phpazure.codeplex.com/license
* Microsoft_Http_Transport_Curl constructor
* @param $httpVerb Http verb to use in the request
* @param $url Url to request
* @param $variables Array of key-value pairs to use in the request
* @param $headers Array of key-value pairs to use as additional headers
* @param $rawBody Raw body to send to server
* @return Microsoft_Http_Response
public function request($httpVerb, $url, $variables = array(), $headers = array(), $rawBody = null)
// Create a new cURL instance
curl_setopt($curlHandle, CURLOPT_FOLLOWLOCATION, true);
// Set HTTP parameters (version and request method)
/*case Microsoft_Http_Transport::VERB_PUT:
curl_setopt($curlHandle, CURLOPT_PUT, true);
// http://stackoverflow.com/questions/770179/php-curl-head-request-takes-a-long-time-on-some-sites
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, 'HEAD');
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, $httpVerb);
// Clear Content-Length header
$headers["Content-Length"] = 0;
// Ensure headers are returned
// Ensure response is returned
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
// Set post fields / raw data
// http://www.php.net/manual/en/function.curl-setopt.php#81161
unset ($headers["Content-Length"]);
$headers["Content-Length"] = strlen($rawBody);
// Set Content-Type header if required
if (!isset ($headers["Content-Type"])) {
$headers["Content-Type"] = '';
// Disable Expect: 100-Continue
// http://be2.php.net/manual/en/function.curl-setopt.php#82418
// Add additional headers to cURL instance
foreach ($headers as $key => $value)
$curlHeaders[] = $key. ': '. $value;
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $curlHeaders);
// DEBUG: curl_setopt($curlHandle, CURLINFO_HEADER_OUT, true);
// DEBUG: var_dump($url);
// DEBUG: var_dump(curl_getinfo($curlHandle,CURLINFO_HEADER_OUT));
// DEBUG: var_dump($rawResponse);
|