コード例 #1
0
 /**
  * Sends a request using the supplied parameters.
  *
  * @param string $url the requested URL
  * @param string $method the HTTP verb to use
  * @param string $postBody the optional POST body to send in the request
  * @param boolean $headers whether or not to return header information
  * @param string $ua the user agent to send in the request
  * @return array the returned data, parsed response headers, and status code
  */
 public function send($url, $method, $postBody = false, $headers = false, $ua = self::USER_AGENT)
 {
     $this->request = array('url' => $url, 'method' => $method, 'body' => $postBody, 'headers' => $headers);
     osapiLogger::info("HTTP Request");
     osapiLogger::info($this->request);
     $response = array_shift($this->responses);
     osapiLogger::info("HTTP Response");
     osapiLogger::info($response);
     return $response;
 }
コード例 #2
0
 /**
  * Sends a request using the supplied parameters.
  *
  * @param string $url the requested URL
  * @param string $method the HTTP verb to use
  * @param string $postBody the optional POST body to send in the request
  * @param boolean $headers whether or not to return header information
  * @param string $ua the user agent to send in the request
  * @return array the returned data, parsed headers, and status code
  */
 public function send($url, $method, $postBody = false, $headers = false, $ua = self::USER_AGENT)
 {
     $ch = curl_init();
     $request = array('url' => $url, 'method' => $method, 'body' => $postBody, 'headers' => $headers);
     osapiLogger::info("HTTP Request");
     osapiLogger::info($request);
     curl_setopt($ch, CURLOPT_URL, $url);
     if ($postBody) {
         curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
     }
     // We need to set method even when we don't have a $postBody 'DELETE'
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_USERAGENT, $ua);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($ch, CURLOPT_HEADER, true);
     if ($headers && is_array($headers)) {
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     }
     $data = @curl_exec($ch);
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $errno = @curl_errno($ch);
     $error = @curl_error($ch);
     @curl_close($ch);
     if ($errno != CURLE_OK) {
         throw new osapiException("HTTP Error: " . $error);
     }
     list($raw_response_headers, $response_body) = explode("\r\n\r\n", $data, 2);
     $response_header_lines = explode("\r\n", $raw_response_headers);
     array_shift($response_header_lines);
     $response_headers = array();
     foreach ($response_header_lines as $header_line) {
         list($header, $value) = explode(': ', $header_line, 2);
         if (isset($response_header_array[$header])) {
             $response_header_array[$header] .= "\n" . $value;
         } else {
             $response_header_array[$header] = $value;
         }
     }
     $response = array('http_code' => $http_code, 'data' => $response_body, 'headers' => $response_header_array);
     osapiLogger::info("HTTP Response");
     osapiLogger::info($response);
     return $response;
 }
コード例 #3
0
 /**
  * Returns the base string of this request
  *
  * The base string defined as the method, the url
  * and the parameters (normalized), each urlencoded
  * and the concated with &.
  */
 public function get_signature_base_string()
 {
     $parts = array($this->get_normalized_http_method(), $this->get_normalized_http_url(), $this->get_signable_parameters());
     $parts = OAuthUtil::urlencode_rfc3986($parts);
     $baseString = implode('&', $parts);
     osapiLogger::info('oauth base string ' . $baseString);
     return $baseString;
 }