/**
  *
  * @param OAuthRequest $Request 
  */
 protected function _Curl($Request)
 {
     $C = curl_init();
     curl_setopt($C, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($C, CURLOPT_SSL_VERIFYPEER, FALSE);
     switch ($Request->get_normalized_http_method()) {
         case 'POST':
             curl_setopt($C, CURLOPT_URL, $Request->get_normalized_http_url());
             curl_setopt($C, CURLOPT_POST, TRUE);
             curl_setopt($C, CURLOPT_POSTFIELDS, $Request->to_postdata());
             break;
         default:
             curl_setopt($C, CURLOPT_URL, $Request->to_url());
     }
     return $C;
 }
 /**
  *
  *
  * @param OAuthRequest $Request
  */
 protected function _curl($Request, $Post = null)
 {
     $C = curl_init();
     curl_setopt($C, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($C, CURLOPT_SSL_VERIFYPEER, false);
     switch ($Request->get_normalized_http_method()) {
         case 'POST':
             //            echo $Request->get_normalized_http_url();
             //            echo "\n\n";
             //            echo $Request->to_postdata();
             curl_setopt($C, CURLOPT_URL, $Request->get_normalized_http_url());
             //            curl_setopt($C, CURLOPT_HTTPHEADER, array('Authorization' => $Request->to_header()));
             curl_setopt($C, CURLOPT_POST, true);
             curl_setopt($C, CURLOPT_POSTFIELDS, $Request->to_postdata());
             break;
         default:
             curl_setopt($C, CURLOPT_URL, $Request->to_url());
     }
     return $C;
 }
Example #3
0
 /**
  * Return the request method
  * 
  * @return string
  */
 public function getMethod()
 {
     return strtoupper($this->_internal_request->get_normalized_http_method());
 }
Example #4
0
 /**
  * Performs a OAuthRequest, returning the response
  * You can give a token to force signatures with this
  * token. If none given, the token used when creating
  * this instance of CampusNotesAPI is used
  * @param OAuthRequest $req
  * @param OAuthToken $token 
  * @return string
  * @throws CNApiException
  */
 private function _performRequest(OAuthRequest $req, OAuthToken $token = null)
 {
     $token = $token ? $token : $this->oauth_token;
     $req->sign_request($this->hmac_signature_method, $this->oauth_consumer, $token);
     $curl = curl_init();
     $params = $req->get_parameters();
     foreach (array_keys($params) as $i) {
         if (substr($i, 0, 6) == 'oauth_') {
             unset($params[$i]);
         }
     }
     $url = $req->get_normalized_http_url();
     if ($req->get_normalized_http_method() == 'POST') {
         curl_setopt($curl, CURLOPT_POST, true);
         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
     } else {
         if (count($params)) {
             $url .= '?' . http_build_query($params);
         }
     }
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array($req->to_header()));
     $rtn = curl_exec($curl);
     if (!$rtn) {
         throw new OAuthClientException(curl_error($curl));
     } else {
         if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) {
             throw new OAuthClientException($rtn);
         } else {
             return $rtn;
         }
     }
 }
Example #5
0
 /**
  * HTTP通信を行う。
  * 
  * @param OAuthRequest $request リクエストオブジェクト
  * @param array $body_params POSTのBODYに指定するパラメータ
  * @return HttpResponse
  */
 private static function http($request, $body_params = array())
 {
     // cURLリソースの生成
     $ch = curl_init();
     // Locationヘッダは無視
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
     // サーバ証明書の検証を行わない
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     // レスポンスを文字列として取得する設定
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // (出力結果に)ヘッダを含める
     curl_setopt($ch, CURLOPT_HEADER, true);
     if (strcasecmp($request->get_normalized_http_method(), 'POST') == 0) {
         // POST通信
         curl_setopt($ch, CURLOPT_POST, true);
         // URLを指定
         curl_setopt($ch, CURLOPT_URL, $request->get_normalized_http_url());
         // リクエストヘッダを設定
         curl_setopt($ch, CURLOPT_HTTPHEADER, array($request->to_header()));
         // リクエストパラメータを設定
         curl_setopt($ch, CURLOPT_POSTFIELDS, $body_params);
     } else {
         // URLを指定
         curl_setopt($ch, CURLOPT_URL, $request->to_url());
     }
     // 実行
     $result = curl_exec($ch);
     // HTTPステータスコードを取得
     $http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     // close curl resource to free up system resources
     curl_close($ch);
     return explode("\r\n\r\n", $result, 2);
 }
Example #6
0
 /**
  * do a request
  *
  * @param OAuthRequest $request
  * @return OAuthToken|null
  */
 private static function doRequest($request)
 {
     if ($request->get_normalized_http_method() == 'POST') {
         $data = self::doPost($request->get_normalized_http_url(), $request->to_postdata());
     } else {
         $data = self::doGet($request->to_url());
     }
     parse_str($data);
     if (isset($oauth_token) && isset($oauth_token_secret)) {
         return new ExtendedOAuthToken($oauth_token, $oauth_token_secret, $data);
     }
     return null;
 }