Пример #1
0
 /**
  * Make a HTTP request.
  *
  * @param string $url    Where to make the
  * @param array  $params post parameters
  *
  * @return mixed the request
  */
 function httpRequest($url, $params = null)
 {
     $request = new HTTPClient($url);
     $request->setConfig(array('connect_timeout' => 120, 'timeout' => 120, 'follow_redirects' => true, 'ssl_verify_peer' => false, 'ssl_verify_host' => false));
     // Twitter is strict about accepting invalid "Expect" headers
     $request->setHeader('Expect', '');
     if (isset($params)) {
         $request->setMethod(HTTP_Request2::METHOD_POST);
         $request->setBody($params);
     }
     try {
         $response = $request->send();
         $code = $response->getStatus();
         if ($code < 200 || $code >= 400) {
             throw new OAuthClientException($response->getBody(), $code);
         }
         return $response->getBody();
     } catch (Exception $e) {
         throw new OAuthClientException($e->getMessage(), $e->getCode());
     }
 }
Пример #2
0
 static function _commonHttp($url, $redirs)
 {
     $request = new HTTPClient($url);
     $request->setConfig(array('connect_timeout' => 10, 'max_redirs' => $redirs, 'follow_redirects' => true, 'store_body' => false));
     return $request;
 }
Пример #3
0
 function postJSON($url, $body)
 {
     $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'POST', $url);
     $request->sign_request($this->sha1_method, $this->consumer, $this->token);
     $hclient = new HTTPClient($url);
     $hclient->setConfig(array('connect_timeout' => 120, 'timeout' => 120, 'follow_redirects' => true, 'ssl_verify_peer' => false, 'ssl_verify_host' => false));
     $hclient->setMethod(HTTP_Request2::METHOD_POST);
     $hclient->setBody(json_encode($body));
     $hclient->setHeader('Content-Type', 'application/json');
     $hclient->setHeader($request->to_header());
     // Twitter is strict about accepting invalid "Expect" headers
     // No reason not to clear it still here -ESP
     $hclient->setHeader('Expect', '');
     try {
         $response = $hclient->send();
         $code = $response->getStatus();
         if (!$response->isOK()) {
             throw new OAuthClientException($response->getBody(), $code);
         }
         return $response;
     } catch (Exception $e) {
         throw new OAuthClientException($e->getMessage(), $e->getCode());
     }
 }