public function citation() { parent::results(); $style = $this->request->getParam("style", false, "mla"); $items = array(); $results = $this->response->get("results"); // header("Content-type: application/json"); $x = 1; foreach ($results->getRecords() as $result) { $id = "ITEM={$x}"; $record = $result->getXerxesRecord()->toCSL(); $record["id"] = $id; $items[$id] = $record; $x++; } $json = json_encode(array("items" => $items)); // header("Content-type: application/json"); echo $json; exit; $url = "http://127.0.0.1:8085?responseformat=html&style={$style}"; $client = new Client(); $client->setUri($url); $client->setHeaders("Content-type: application/json"); $client->setHeaders("Expect: nothing"); $client->setRawData($json)->setEncType('application/json'); $response = $client->request('POST')->getBody(); echo $response; exit; }
/** * This function checks if a newer version of livetest is avaiable. * * @Event("LiveTest.Runner.Init") * * @param array $arguments * @param Event $event */ public function doUpgradeCheck($arguments, Event $event) { if (array_key_exists('check-upgrade', $arguments)) { echo ' Checking for upgrade (current version ' . LIVETEST_VERSION . '): '; $zend = new Client(self::PHM_API); $zend->setAdapter(new Curl()); $latestStable = trim($zend->request()->getBody()); if (version_compare(LIVETEST_VERSION, $latestStable, '<')) { echo 'Newer version found (latest stable: ' . $latestStable . ").\n" . ' Please visit livetest.www.phmlabs.com for more information.'; } else { echo 'No newer version found (latest stable: ' . $latestStable . ')'; } $event->setProcessed(); } }
public function request(Request $request) { $method = $request->getMethod(); $parameters = $request->getParameters(); $this->setUri($request->getUri()); if (!strcasecmp($method, Request::GET)) { $this->setParameterGet($parameters); } else { if (!strcasecmp($method, Request::POST)) { $this->setParameterPost($parameters); } } $this->setTimeout(1); $timer = new Timer(); $response = parent::request($method); $duration = $timer->stop(); return new \Base\Http\Response\Zend($response, $duration); }
/** * @todo use POST request instead of mailing (works for dev images) * * @Event("LiveTest.Runner.Error") * * @param \Exception $e */ public function handleException(\Exception $exception) { $this->exception = $exception; if (!$this->isUserSpace($this->exception)) { if ($this->sendFeedback) { try { $feedback = array(); $feedback = $this->createAttachment(); $zend = new Client(self::PHM_API); $zend->setAdapter(new Curl()); $zend->setParameterPost('feedback', $feedback); $zend->request('POST'); echo "\n\n All error related informations were sent. Thank you for helping to improve LiveTest."; } catch (\Exception $e) { echo "\n\n Unable to send feedback (" . $e->getMessage() . ")"; } } else { echo "\n\n If this error occurs again please use the --feedback argument to send all \n" . " error related information to our team."; } } }
/** * {@inheritdoc} */ public function write($path, $contents, Config $config) { $location = $this->applyPathPrefix($path); prn($path, $contents, $config, $location, dirname($location)); $this->client->setMethod('POST'); $this->client->setUri($this->api_url); $this->client->setParameterPOST(array_merge($this->auth_param, ['filename' => $path])); file_put_contents('tmp', $contents); $this->client->setFileUpload('tmp', 'form'); $response = $this->client->send(); if ($response->getStatusCode() != 200) { throw new \Exception(json_decode($response->getBody())->message); } prn($response->getContent()); return json_decode($response->getContent())->data->{$filename}; $location = $this->applyPathPrefix($path); $this->client->request('PUT', $location, $contents); $result = compact('path', 'contents'); if ($config->get('visibility')) { throw new LogicException(__CLASS__ . ' does not support visibility settings.'); } return $result; }
/** * Performs a HTTP request using the specified method * * @param string $method The HTTP method for the request - 'GET', 'POST', * 'PUT', 'DELETE' * @param string $url The URL to which this request is being performed * @param array $headers An associative array of HTTP headers * for this request * @param string $body The body of the HTTP request * @param string $contentType The value for the content type * of the request body * @param int $remainingRedirects Number of redirects to follow if request * s results in one * @return \Zend\Http\Response The response object */ public function performHttpRequest($method, $url, $headers = null, $body = null, $contentType = null, $remainingRedirects = null) { if ($remainingRedirects === null) { $remainingRedirects = self::getMaxRedirects(); } if ($headers === null) { $headers = array(); } // Append a Gdata version header if protocol v2 or higher is in use. // (Protocol v1 does not use this header.) $major = $this->getMajorProtocolVersion(); $minor = $this->getMinorProtocolVersion(); if ($major >= 2) { $headers['GData-Version'] = $major + ($minor === null ? '.' + $minor : ''); } // check the overridden method if (($method == 'POST' || $method == 'PUT') && $body === null && $headers['x-http-method-override'] != 'DELETE') { throw new App\InvalidArgumentException('You must specify the data to post as either a ' . 'string or a child of Zend\\GData\\App\\Entry'); } if ($url === null) { throw new App\InvalidArgumentException('You must specify an URI to which to post.'); } $headers['Content-Type'] = $contentType; if (self::getGzipEnabled()) { // some services require the word 'gzip' to be in the user-agent // header in addition to the accept-encoding header if (strpos($this->_httpClient->getHeader('User-Agent'), 'gzip') === false) { $headers['User-Agent'] = $this->_httpClient->getHeader('User-Agent') . ' (gzip)'; } $headers['Accept-encoding'] = 'gzip, deflate'; } else { $headers['Accept-encoding'] = 'identity'; } // Make sure the HTTP client object is 'clean' before making a request // In addition to standard headers to reset via resetParameters(), // also reset the Slug and If-Match headers $this->_httpClient->resetParameters(); $this->_httpClient->setHeaders(array('Slug', 'If-Match')); // Set the params for the new request to be performed $this->_httpClient->setHeaders($headers); $urlObj = new \Zend\Uri\Url($url); preg_match("/^(.*?)(\\?.*)?\$/", $url, $matches); $this->_httpClient->setUri($matches[1]); $queryArray = $urlObj->getQueryAsArray(); foreach ($queryArray as $name => $value) { $this->_httpClient->setParameterGet($name, $value); } $this->_httpClient->setConfig(array('maxredirects' => 0)); // Set the proper adapter if we are handling a streaming upload $usingMimeStream = false; $oldHttpAdapter = null; if ($body instanceof \Zend\GData\MediaMimeStream) { $usingMimeStream = true; $this->_httpClient->setRawDataStream($body, $contentType); $oldHttpAdapter = $this->_httpClient->getAdapter(); if ($oldHttpAdapter instanceof \Zend\Http\Client\Adapter\Proxy) { $newAdapter = new HttpAdapterStreamingProxy(); } else { $newAdapter = new HttpAdapterStreamingSocket(); } $this->_httpClient->setAdapter($newAdapter); } else { $this->_httpClient->setRawData($body, $contentType); } try { $response = $this->_httpClient->request($method); // reset adapter if ($usingMimeStream) { $this->_httpClient->setAdapter($oldHttpAdapter); } } catch (\Zend\Http\Client\Exception $e) { // reset adapter if ($usingMimeStream) { $this->_httpClient->setAdapter($oldHttpAdapter); } throw new App\HttpException($e->getMessage(), $e); } if ($response->isRedirect() && $response->getStatus() != '304') { if ($remainingRedirects > 0) { $newUrl = $response->getHeader('Location'); $response = $this->performHttpRequest($method, $newUrl, $headers, $body, $contentType, $remainingRedirects); } else { throw new App\HttpException('Number of redirects exceeds maximum', null, $response); } } if (!$response->isSuccessful()) { $exceptionMessage = 'Expected response code 200, got ' . $response->getStatus(); if (self::getVerboseExceptionMessages()) { $exceptionMessage .= "\n" . $response->getBody(); } $exception = new App\HttpException($exceptionMessage); $exception->setResponse($response); throw $exception; } return $response; }
/** * Same as Zend_HTTP_Client::request() except just before the request is * executed, we automatically append any necessary OAuth parameters and * sign the request using the relevant signature method. * * @param string $method * @return Zend\Http\Response */ public function request($method = null) { if (!is_null($method)) { $this->setMethod($method); } $this->prepareOAuth(); return parent::request(); }
/** * Performs an HTTP GET request to the $path. * * @param string $path * @param array $query Array of GET parameters * @throws \Zend\Http\Client\Exception * @return \Zend\Http\Response */ protected function _get($path, array $query = null) { $this->_prepare($path); $this->_localHttpClient->setParameterGet($query); return $this->_localHttpClient->request(Http\Client::GET); }
$counter++; // ----------------------------------------------------------------------------- if (extension_loaded('libxml')) { $version = LIBXML_DOTTED_VERSION; $result = TEST_PASS; } else { $version = 'N/A'; $result = TEST_FAIL; $failed = true; } Helper::printLineToc($counter, sprintf('Checking libXML extension (%s)', $version), $result); $counter++; unset($version); // ----------------------------------------------------------------------------- $httpClient->setUri(GEOIP_SERVICE_URI); $httpResponse = $httpClient->request(); if ($httpResponse->isSuccessful()) { $keys = array('Ip' => 'IP address', 'City' => 'city', 'RegionName' => 'region', 'CountryName' => 'country'); $simplexml = new SimpleXMLElement($httpResponse->getBody()); foreach ($keys as $key => $value) { Helper::printLineToc($counter, sprintf('Checking your %s (%s)', $keys[$key], $simplexml->{$key}), TEST_PASS); $counter++; } } else { Helper::printLineToc($counter, 'Checking your geo data', TEST_FAIL); $failed = true; } // ----------------------------------------------------------------------------- $microtime = microtime(true); $httpClient->setUri(MailMerge::WSDL); if ($httpClient->request()->isSuccessful()) {
/** * Testing if the connection can be closed * * @group ZF-9685 */ public function testOpenTempStreamWithBogusFileClosesTheConnection() { $this->setExpectedException( 'Zend\Http\Client\Exception\RuntimeException', 'Could not open temp file /path/to/bogus/file.ext'); $url = 'http://www.example.com'; $config = array ( 'output_stream' => '/path/to/bogus/file.ext', ); $client = new HTTPClient($url, $config); $result = $client->request(); }
/** * Testing if the connection can be closed * * @group ZF-9685 * @expectedException \Zend\Http\Client\Exception */ public function testOpenTempStreamWithBogusFileClosesTheConnection() { $url = 'http://www.example.com'; $config = array('output_stream' => '/path/to/bogus/file.ext'); $client = new HTTPClient($url, $config); $result = $client->request(); }
/** * Pingback * * @param string $source ページのPing送信用のアドレス * @param string $target ページのPing待受用のアドレス * @return int */ public function ping($source, $target) { // Zend\Uri\Uriオブジェクトを生成 $source_url = Uri::factory($source); $target_url = Uri::factory($target); // 無効なアドレス if (!$target_url->isValid()) { return self::RESPONSE_FAULT_TARGET_INVALID; } if (!$source_url->isValid()) { return self::RESPONSE_FAULT_GENERIC; } if ($target_url->getHost() === $source_url->getHost()) { // ターゲットとソースのホストが一緒 // TODO: 同じドメインのサイトの場合、同じサイトとみなされる return self::RESPONSE_FAULT_SOURCE; } // 相手のサイトに接続 $source_client = new Client($source_url); $source_response = $source_client->request(Client::GET); // 接続できたかをチェック if (!$source_response->isSuccessful()) { return self::RESPONSE_FAULT_SOURCE; } // 相手のサイトの中身を取得 $source_body = $source_response->getBody(); // 中身を取得できない if (!$source_body) { return self::RESPONSE_FAULT_SOURCE; } if ($target_url->getHost() !== $source_url->getHost() && strpos($source_body, $source_url) === false) { // ソース URI のデータにターゲット URI へのリンクが存在しないため、ソースとして使用できない。 return self::RESPONSE_FAULT_SOURCE_LINK; } // 相手サイトのタイトルを取得(XMLとして処理した方がいい?) $source_titles = array(); preg_match('/<title>([^<]*?)</title>/is', $source_body, $source_titles); // タイトルが存在しないUntitled $source_title = empty($source_titles[1]) ? self::UNTITLED_TITLE : $source_titles[1]; // ターゲットのクエリを取得(自サイト) $query = $target_url->getQuery(); if (empty($query)) { // http://[host]/[pagename]の場合(スラッシュは再エンコード) $r_page = str_replace('/', '%2F', $target_url->getPath()); // $url_suffixが含まれる場合、正規表現でそこを削除 //$page = empty($url_suffix) ? $r_page : preg_replace('/'.$url_suffix.'$/', '', $r_page); $page = rawurldecode($r_page); unset($r_page); } else { // ターゲットに=が含まれる場合はページではないので無効 if (strpbrk($query, '=')) { return self::RESPONSE_FAULT_TARGET_INVALID; } $page = $query; } // ページ名からWikiを呼び出す $wiki = Factory::Wiki($page); if (!$wiki->isValied()) { // 無効なページ名 return self::RESPONSE_FAULT_TARGET_INVALID; } if (!$wiki->isReadable()) { // 読み込み不可なページ return self::RESPONSE_FAULT_ACCESS_DENIED; } // PingBackファイルを読み込む $pb = new PingBackFile($page); $lines = $pb->get(); if (count($lines) !== 0) { foreach ($lines as $line) { list($time, $url, $title) = explode("\t", $line); if ($url === $target_url) { // すでに登録されている return self::RESPONSE_FAULT_ALREADY_REGISTERED; } } } // 新しいデーターを登録 $lines[] = join("\t", array(UTIME, $source_url, $source_title)); // 保存 $pb->set($lines); return self::RESPONSE_SUCCESS; }