本文整理汇总了PHP中HTTP_Request2类的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request2类的具体用法?PHP HTTP_Request2怎么用?PHP HTTP_Request2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTP_Request2类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: erzData
public function erzData($zip = null, $type = null, $page = 1)
{
if ($type) {
$url = 'http://openerz.herokuapp.com:80/api/calendar/' . $type . '.json';
} else {
$url = 'http://openerz.herokuapp.com:80/api/calendar.json';
}
//Http-request
$request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
$reqUrl = $request->getUrl();
$pageSize = 10;
$reqUrl->setQueryVariable('limit', $pageSize);
$offset = ($page - 1) * $pageSize;
$reqUrl->setQueryVariable('offset', $offset);
if ($zip) {
$reqUrl->setQueryVariable('zip', $zip);
}
try {
$response = $request->send();
// 200 ist für den Status ob ok ist 404 wäre zum Beispiel ein Fehler
if ($response->getStatus() == 200) {
return json_decode($response->getBody());
}
} catch (HTTP_Request2_Exception $ex) {
echo $ex;
}
return null;
}
开发者ID:Nithuja,项目名称:ERZ,代码行数:28,代码来源:index.php
示例2: main
/**
* Make the GET request
*
* @throws BuildException
*/
public function main()
{
if (!isset($this->url)) {
throw new BuildException("Missing attribute 'url'");
}
if (!isset($this->dir)) {
throw new BuildException("Missing attribute 'dir'");
}
$this->log("Fetching " . $this->url);
$request = new HTTP_Request2($this->url);
$response = $request->send();
if ($response->getStatus() != 200) {
throw new BuildException("Request unsuccessfull. Response from server: " . $response->getStatus() . " " . $response->getReasonPhrase());
}
$content = $response->getBody();
if ($this->filename) {
$filename = $this->filename;
} elseif ($disposition = $response->getHeader('content-disposition') && 0 == strpos($disposition, 'attachment') && preg_match('/filename="([^"]+)"/', $disposition, $m)) {
$filename = basename($m[1]);
} else {
$filename = basename(parse_url($this->url, PHP_URL_PATH));
}
if (!is_writable($this->dir)) {
throw new BuildException("Cannot write to directory: " . $this->dir);
}
$filename = $this->dir . "/" . $filename;
file_put_contents($filename, $content);
$this->log("Contents from " . $this->url . " saved to {$filename}");
}
开发者ID:altesien,项目名称:FinalProject,代码行数:34,代码来源:HttpGetTask.php
示例3: __construct
private function __construct()
{
// sanity check
$siteUrl = get_option('siteurl');
$layoutUrl = DAIQUIRI_URL . '/core/layout/';
if (strpos($layoutUrl, $siteUrl) !== false) {
echo '<h1>Error with theme</h1><p>Layout URL is below CMS URL.</p>';
die(0);
}
// construct request
require_once 'HTTP/Request2.php';
$req = new HTTP_Request2($layoutUrl);
$req->setConfig(array('ssl_verify_peer' => false, 'connect_timeout' => 2, 'timeout' => 3));
$req->setMethod('GET');
$req->addCookie("PHPSESSID", $_COOKIE["PHPSESSID"]);
try {
$response = $req->send();
if (200 != $response->getStatus()) {
echo '<h1>Error with theme</h1><p>HTTP request status != 200.</p>';
die(0);
}
} catch (HTTP_Request2_Exception $e) {
echo '<h1>Error with theme</h1><p>Error with HTTP request.</p>';
die(0);
}
$body = explode('<!-- content -->', $response->getBody());
if (count($body) == 2) {
$this->_header = $body[0];
$this->_footer = $body[1];
} else {
echo '<h1>Error with theme</h1><p>Malformatted layout.</p>';
die(0);
}
}
开发者ID:vrtulka23,项目名称:daiquiri,代码行数:34,代码来源:functions.php
示例4: sendRequest
/**
* {@inheritdoc }
*/
public function sendRequest(\HTTP_Request2 $request)
{
if (array_key_exists($request->getMethod(), array_flip($this->getDisallowedMethods()))) {
throw new NotAllowedMethodTypeException();
}
return parent::sendRequest($request);
}
开发者ID:mobilerider,项目名称:mobilerider-client-php,代码行数:10,代码来源:BaseAdapter.php
示例5: getRss
function getRss($url, $port, $timeout)
{
$results = array('rss' => array(), 'error' => "");
try {
$request = new HTTP_Request2($url, HTTP_Request2::METHOD_POST);
$request->setConfig("connect_timeout", $timeout);
$request->setConfig("timeout", $timeout);
$request->setHeader("user-agent", $_SERVER['HTTP_USER_AGENT']);
$response = $request->send();
if ($response->getStatus() == 200) {
// パース
$body = $response->getBody();
if (substr($body, 0, 5) == "<?xml") {
$results['rss'] = new MagpieRSS($body, "UTF-8");
} else {
throw new Exception("Not xml data");
}
} else {
throw new Exception("Server returned status: " . $response->getStatus());
}
} catch (HTTP_Request2_Exception $e) {
$results['error'] = $e->getMessage();
} catch (Exception $e) {
$results['error'] = $e->getMessage();
}
// タイムアウト戻し
ini_set('default_socket_timeout', $oldtimeout);
return $results;
}
开发者ID:homework-bazaar,项目名称:zencart-sugu,代码行数:29,代码来源:functions.php
示例6: testSetRequest
public function testSetRequest()
{
$newswire = new Newswire('apikey');
$req = new \HTTP_Request2();
$req->setAdapter('mock');
$this->assertInstanceOf('PEAR2\\Services\\NYTimes\\Newswire', $newswire->accept($req));
}
开发者ID:pear2,项目名称:services_nytimes,代码行数:7,代码来源:BaseTest.php
示例7: setUp
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @return void
*/
protected function setUp()
{
$this->mock = new HTTP_Request2_Adapter_Mock();
$request = new HTTP_Request2();
$request->setAdapter($this->mock);
$this->validator = new Services_W3C_CSSValidator($request);
}
开发者ID:pear,项目名称:services_w3c_cssvalidator,代码行数:13,代码来源:Services_W3C_CSSValidatorTest.php
示例8: getLanguagesFromTransifex
public function getLanguagesFromTransifex()
{
$request = new HTTP_Request2('http://vela1606:[email protected]/api/2/project/gaiaehr/resource/All/?details', HTTP_Request2::METHOD_GET);
$r = $request->send()->getBody();
$r = json_decode($r, true);
return array('langs' => $r['available_languages']);
}
开发者ID:nhom5UET,项目名称:tichhophethong,代码行数:7,代码来源:Languages.php
示例9: fetchLunchMenus
/**
* さくら水産のランチ情報を取得する
*
* @return array | false
*/
public function fetchLunchMenus()
{
$menus = array();
$today = new DateTime();
$request = new HTTP_Request2();
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setUrl(self::LUNCHMENU_URL);
try {
$response = $request->send();
if (200 == $response->getStatus()) {
$dom = new DOMDocument();
@$dom->loadHTML($response->getBody());
$xml = simplexml_import_dom($dom);
foreach ($xml->xpath('//table/tr') as $tr) {
if (preg_match('/(\\d+)月(\\d+)日/', $tr->td[0]->div, $matches)) {
$dateinfo = new DateTime(sprintf('%04d-%02d-%02d', $today->format('Y'), $matches[1], $matches[2]));
$_menus = array();
foreach ($tr->td[1]->div->strong as $strong) {
$_menus[] = (string) $strong;
}
$menus[$dateinfo->format('Y-m-d')] = $_menus;
}
}
}
} catch (HTTP_Request2_Exception $e) {
// HTTP Error
return false;
}
return $menus;
}
开发者ID:riaf,项目名称:Wozozo_Sakusui,代码行数:35,代码来源:Sakusui.php
示例10: send_post_data
function send_post_data($url, $data)
{
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2($url);
$request->setMethod(HTTP_Request2::METHOD_POST)->addPostParameter($data);
return $request->send();
}
开发者ID:jabouzi,项目名称:belron,代码行数:7,代码来源:functions_helper.php
示例11: twipic
function twipic($f, $a, $b, $m)
{
$twitpic_api = "";
$consumer_key = "";
$consumer_secret = "";
$access_token = $a;
$access_token_secret = $b;
$imagepath = $f;
$message = $me;
$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer->setToken($access_token);
$consumer->setTokenSecret($access_token_secret);
$http_request = new HTTP_Request2();
$http_request->setConfig('ssl_verify_peer', false);
$consumer_request = new HTTP_OAuth_Consumer_Request();
$consumer_request->accept($http_request);
$consumer->accept($consumer_request);
$resp = $consumer->sendRequest('https://api.twitter.com/1.1/account/verify_credentials.json', array(), HTTP_Request2::METHOD_GET);
$headers = $consumer->getLastRequest()->getHeaders();
$http_request->setHeader('X-Auth-Service-Provider', 'https://api.twitter.com/1.1/account/verify_credentials.json');
$http_request->setHeader('X-Verify-Credentials-Authorization', $headers['authorization']);
$http_request->setUrl('http://api.twitpic.com/2/upload.json');
$http_request->setMethod(HTTP_Request2::METHOD_POST);
$http_request->addPostParameter('key', $twitpic_api);
$http_request->addPostParameter('message', $m);
$http_request->addUpload('media', $imagepath);
$resp = $http_request->send();
$body = $resp->getBody();
$body = json_decode($body, true);
return $body;
}
开发者ID:book000,项目名称:mcmn,代码行数:31,代码来源:twipic.php
示例12: setRequestHeaders
/**
* Sets the common headers required by CloudFront API
* @param HTTP_Request2 $req
*/
private function setRequestHeaders(HTTP_Request2 $req)
{
$date = gmdate("D, d M Y G:i:s T");
$req->setHeader("Host", 'cloudfront.amazonaws.com');
$req->setHeader("Date", $date);
$req->setHeader("Authorization", $this->generateAuthKey($date));
$req->setHeader("Content-Type", "text/xml");
}
开发者ID:subchild,项目名称:CloudFront-PHP-Invalidator,代码行数:12,代码来源:CloudFront.php
示例13: testConfigurationViaProperties
public function testConfigurationViaProperties()
{
$trace = new TraceHttpAdapter();
$this->copyTasksAddingCustomRequest('config-properties', 'recipient', $this->createRequest($trace));
$this->executeTarget('recipient');
$request = new HTTP_Request2(null, 'GET', array('proxy' => 'http://localhost:8080/', 'max_redirects' => 9));
$this->assertEquals($request->getConfig(), $trace->requests[0]['config']);
}
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:8,代码来源:HttpRequestTaskTest.php
示例14: addHttpMock
protected function addHttpMock(Net_WebFinger $wf)
{
$this->adapter = new HTTP_Request2_Adapter_LogMock();
$req = new HTTP_Request2();
$req->setAdapter($this->adapter);
$wf->setHttpClient($req);
return $this;
}
开发者ID:mitgedanken,项目名称:Net_WebFinger,代码行数:8,代码来源:WebFingerTestBase.php
示例15: testBug17826
public function testBug17826()
{
$adapter = new HTTP_Request2_Adapter_Socket();
$request1 = new HTTP_Request2($this->baseUrl . 'redirects.php?redirects=2');
$request1->setConfig(array('follow_redirects' => true, 'max_redirects' => 3))->setAdapter($adapter)->send();
$request2 = new HTTP_Request2($this->baseUrl . 'redirects.php?redirects=2');
$request2->setConfig(array('follow_redirects' => true, 'max_redirects' => 3))->setAdapter($adapter)->send();
}
开发者ID:rogerwu99,项目名称:punch_bantana,代码行数:8,代码来源:SocketTest.php
示例16: update
public static function update($userid)
{
global $HTTP_CONFIG;
$username = Token::get(self::name, $userid);
$request = new HTTP_Request2('http://open.dapper.net/transform.php?dappName=CodeChefProblemsSolved&transformer=JSON&v_username=' . $username);
$request->setConfig($HTTP_CONFIG);
$response = $request->send()->getBody();
$score = json_decode($response)->fields->solved[32]->value;
Score::update(self::name, $userid, $score);
}
开发者ID:nsystem1,项目名称:leaderboard,代码行数:10,代码来源:codechef.php
示例17: etcd_get
private function etcd_get($url, $base = false)
{
$base = $base === false ? $this->etcd_base : $base;
/* Get some key from etcd */
$etcd_url = explode(",", getenv("ETCDCTL_PEERS"))[0] . "/v2/keys" . $base . $url;
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2($etcd_url, HTTP_Request2::METHOD_GET);
$res = $request->send();
return json_decode($res->getBody());
}
开发者ID:panubo,项目名称:docker-php-apache,代码行数:10,代码来源:ServiceDiscovery.php
示例18: testGetException
/**
* @expectedException Services_Yadis_Exception
* @expectedExceptionMessage Invalid response to Yadis protocol received: A test error
*/
public function testGetException()
{
$httpMock = new HTTP_Request2_Adapter_Mock();
$httpMock->addResponse(new HTTP_Request2_Exception('A test error', 500));
$http = new HTTP_Request2();
$http->setAdapter($httpMock);
$sy = new Services_Yadis('http://example.org/openid');
$sy->setHttpRequest($http);
$xrds = $sy->discover();
}
开发者ID:pear,项目名称:services_yadis,代码行数:14,代码来源:YadisTest.php
示例19: update
public static function update($userid)
{
global $HTTP_CONFIG;
$username = Token::get(self::name, $userid);
$request = new HTTP_Request2('https://hacker-news.firebaseio.com/v0/user/' . $username . '.json');
$request->setConfig($HTTP_CONFIG);
$response = $request->send()->getBody();
$karma = json_decode($response)->karma;
Score::update(self::name, $userid, $karma);
}
开发者ID:nsystem1,项目名称:leaderboard,代码行数:10,代码来源:hackernews.php
示例20: update
public static function update($userid)
{
global $HTTP_CONFIG;
$twitterScreenName = Token::get(self::name, $userid);
$request = new HTTP_Request2('https://api.twitter.com/1/users/show.json?screen_name=' . $twitterScreenName);
$request->setConfig($HTTP_CONFIG);
$response = $request->send()->getBody();
$followers_count = json_decode($response)->followers_count;
Score::update(self::name, $userid, $followers_count);
//Update in database
}
开发者ID:nsystem1,项目名称:leaderboard,代码行数:11,代码来源:twitter.php
注:本文中的HTTP_Request2类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论