当前位置: 首页>>代码示例>>PHP>>正文


PHP HTTPClient::setMethod方法代码示例

本文整理汇总了PHP中HTTPClient::setMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTPClient::setMethod方法的具体用法?PHP HTTPClient::setMethod怎么用?PHP HTTPClient::setMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTTPClient的用法示例。


在下文中一共展示了HTTPClient::setMethod方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: httpClient

 /**
  * Set up an HTTPClient with auth for our resource.
  *
  * @param string $method
  * @return HTTPClient
  */
 private function httpClient($method = 'GET')
 {
     $client = new HTTPClient($this->url);
     $client->setMethod($method);
     $client->setAuth($this->user, $this->pass);
     return $client;
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:13,代码来源:atompub_test.php

示例2: httpRequest

 /**
  * 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());
     }
 }
开发者ID:himmelex,项目名称:NTW,代码行数:29,代码来源:oauthclient.php

示例3: postToCollection

 function postToCollection($url, $activity)
 {
     $client = new HTTPClient($url);
     $client->setMethod('POST');
     $client->setAuth($this->username, $this->password);
     $client->setHeader('Content-Type', 'application/atom+xml;type=entry');
     $client->setBody($activity->asString(true, true, true));
     $response = $client->send();
     $status = $response->getStatus();
     $reason = $response->getReasonPhrase();
     if ($status >= 200 && $status < 300) {
         return true;
     } else {
         if ($status >= 400 && $status < 500) {
             // TRANS: Client exception thrown when post to collection fails with a 400 status.
             // TRANS: %1$s is a URL, %2$s is the status, %s$s is the fail reason.
             throw new ClientException(sprintf(_m('URLSTATUSREASON', '%1$s %2$s %3$s'), $url, $status, $reason));
         } else {
             if ($status >= 500 && $status < 600) {
                 // TRANS: Server exception thrown when post to collection fails with a 500 status.
                 // TRANS: %1$s is a URL, %2$s is the status, %s$s is the fail reason.
                 throw new ServerException(sprintf(_m('URLSTATUSREASON', '%1$s %2$s %3$s'), $url, $status, $reason));
             } else {
                 // That's unexpected.
                 // TRANS: Exception thrown when post to collection fails with a status that is not handled.
                 // TRANS: %1$s is a URL, %2$s is the status, %s$s is the fail reason.
                 throw new Exception(sprintf(_m('URLSTATUSREASON', '%1$s %2$s %3$s'), $url, $status, $reason));
             }
         }
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:31,代码来源:activitysink.php

示例4: postJSON

 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());
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:24,代码来源:spamfilter.php


注:本文中的HTTPClient::setMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。