本文整理汇总了PHP中Guzzle\Http\Message\Request::getUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getUrl方法的具体用法?PHP Request::getUrl怎么用?PHP Request::getUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::getUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isTestConnection
/**
* is test connection
* @return boolean
*/
private function isTestConnection()
{
$url = $this->request->getUrl(true);
if ($url->getPath() == '/k/v1/form.json' && $url->getQuery()->get('app') == -1) {
// 通信テスト成功
return true;
}
return false;
}
示例2: printResult
public function printResult()
{
echo sprintf('%s %s : %s calls', strtoupper($this->request->getMethod()), $this->request->getUrl(), $this->nbCalls) . PHP_EOL;
foreach ($this->httpTimeDataCollector->getIterator() as $httpTimeResult) {
echo sprintf('total time = %s ms', $httpTimeResult) . PHP_EOL;
}
echo '--- statistics ---' . PHP_EOL;
echo sprintf('results filter on %s percentile', $this->httpTimeDataCollector->getPercentile()) . PHP_EOL;
echo sprintf('min/avg/max = %s/%s/%s ms', $this->httpTimeDataCollector->getMinTime(), $this->httpTimeDataCollector->getAverageTime(), $this->httpTimeDataCollector->getMaxTime()) . PHP_EOL;
}
示例3: testOnRequestBeforeSendPOST
public function testOnRequestBeforeSendPOST()
{
$request = new Request('POST', 'www.url.com');
$event = new Event(array('request' => $request));
$this->plugin->onRequestBeforeSend($event);
$this->assertContains('key=' . $this->key, $request->getUrl());
}
示例4: testUrlEncodedSignature
/**
* Guzzle should take care of encoding signatures. This test is just a safety net to ensure that happens.
*/
public function testUrlEncodedSignature()
{
$expected = '1234 ] 5678';
$request = new Request('GET', "/fake?signature={$expected}");
$url = explode('signature=', $request->getUrl());
$signature = end($url);
$this->assertEquals(rawurlencode($expected), $signature, 'Request should be encoding the signature before sending (required by Ooyala).');
}
示例5: addAuthenticationHeaders
/**
* Sign the current request for write operations
*
* @param Request $request The current request
*/
private function addAuthenticationHeaders(Request $request)
{
$client = $request->getClient();
// Get a GMT/UTC timestamp
$timestamp = gmdate('Y-m-d\\TH:i:s\\Z');
// Build the data to base the hash on
$data = $request->getMethod() . '|' . $request->getUrl() . '|' . $client->getConfig('publicKey') . '|' . $timestamp;
// Generate signature
$signature = hash_hmac('sha256', $data, $client->getConfig('privateKey'));
// Add relevant request headers (overwriting once that might already exist)
$request->setHeader('X-Imbo-Authenticate-Signature', $signature);
$request->setHeader('X-Imbo-Authenticate-Timestamp', $timestamp);
}
示例6: sendRequest
/**
* Function to send the request to the remote API
*
* @return \Trucker\Responses\Response
*/
public function sendRequest()
{
try {
$response = $this->request->send();
} catch (\Guzzle\Http\Exception\BadResponseException $e) {
$response = $e->getResponse();
}
if (Config::get('request.debug', false)) {
echo 'Request Method: ' . $this->request->getMethod() . "\n";
echo "Body: " . $response->getBody() . "\n";
echo "Status Code: " . $response->getStatusCode() . "\n";
echo "URL: " . $this->request->getUrl() . "\n\n";
}
return $this->app->make('trucker.response')->newInstance($this->app, $response);
}
示例7: generateAuthHeader
private function generateAuthHeader(Request $request, $timestamp, $nonce)
{
$url = $request->getUrl();
$hash = $this->getSHA1(md5(self::$consumer_secret), $this->urlencode($url));
$headers = ['OAuth realm' => ''];
$headers[self::$keys['OAuthVersionKey']] = self::$oAuthVersion;
$headers[self::$keys['OAuthTimestampKey']] = $timestamp;
$headers[self::$keys['OAuthNonceKey']] = $nonce;
$headers[self::$keys['OAuthSignatureMethodKey']] = 'HMAC-SHA1';
$headers[self::$keys['OAuthConsumerKeyKey']] = self::$consumer_key;
$headers[self::$keys['OAuthSignatureKey']] = $hash;
$h = [];
foreach ($headers as $name => $value) {
$h[] = $name . '="' . $value . '"';
}
return implode(',', $h);
}
示例8: send
private function send(Request $request)
{
try {
$this->logger and $this->logger->debug(sprintf('%s "%s"', $request->getMethod(), $request->getUrl()));
$this->logger and $this->logger->debug(sprintf("Request:\n%s", (string) $request));
$response = $this->client->send($request);
$this->logger and $this->logger->debug(sprintf("Response:\n%s", (string) $response));
return $response;
} catch (ClientErrorResponseException $e) {
$this->logException($e);
$statusCode = $e->getResponse()->getStatusCode();
$reasonPhrase = $e->getResponse()->getReasonPhrase();
$message = sprintf('The request is not valid (status code: "%d", reason phrase: "%s").', $statusCode, $reasonPhrase);
throw new ApiClientException($message, 0, $e);
} catch (BadResponseException $e) {
$this->logException($e);
throw new ApiServerException('Something went wrong with upstream.', 0, $e);
}
}
示例9: printLastResponseOnError
/**
* @AfterScenario
*/
public function printLastResponseOnError(BaseScenarioEvent $scenarioEvent)
{
if ($scenarioEvent->getResult() == StepEvent::FAILED) {
if ($this->response) {
$body = $this->getResponse()->getBody(true);
// could we even ask them if they want to print out the error?
// or do it based on verbosity
// print some debug details
$this->printDebug('');
$this->printDebug('<error>Failure!</error> when making the following request:');
$this->printDebug(sprintf('<comment>%s</comment>: <info>%s</info>', $this->lastRequest->getMethod(), $this->lastRequest->getUrl()) . "\n");
if ($this->response->isContentType('application/json') || $this->response->isContentType('+json')) {
$data = json_decode($body);
if ($data === null) {
// invalid JSON!
$this->printDebug($body);
} else {
// valid JSON, print it pretty
$this->printDebug(json_encode($data, JSON_PRETTY_PRINT));
}
} else {
// the response is HTML - see if we should print all of it or some of it
$isValidHtml = strpos($body, '</body>') !== false;
if ($this->useFancyExceptionReporting && $isValidHtml) {
$this->printDebug('<error>Failure!</error> Below is a summary of the HTML response from the server.');
// finds the h1 and h2 tags and prints them only
$crawler = new Crawler($body);
foreach ($crawler->filter('h1, h2')->extract(array('_text')) as $header) {
$this->printDebug(sprintf(' ' . $header));
}
} else {
$this->printDebug($body);
}
}
}
}
}
示例10: deEncodeRequestUrl
/**
*
* @param \Guzzle\Http\Message\Request $request
* @return \Guzzle\Http\Message\Request
*/
private function deEncodeRequestUrl(\Guzzle\Http\Message\Request $request)
{
// Intentionally not a one-liner to make the process easier to understand
$requestUrl = $request->getUrl(true);
$requestQuery = $requestUrl->getQuery(true);
$requestQuery->useUrlEncoding(false);
$requestUrl->setQuery($requestQuery);
$request->setUrl($requestUrl);
return $request;
}
示例11: setRequestCookies
/**
*
* @param \Guzzle\Http\Message\Request $request
*/
private function setRequestCookies(\Guzzle\Http\Message\Request $request)
{
if (!is_null($request->getCookies())) {
foreach ($request->getCookies() as $name => $value) {
$request->removeCookie($name);
}
}
$cookieUrlMatcher = new \webignition\Cookie\UrlMatcher\UrlMatcher();
foreach ($this->getConfiguration()->getCookies() as $cookie) {
if ($cookieUrlMatcher->isMatch($cookie, $request->getUrl())) {
$request->addCookie($cookie['name'], $cookie['value']);
}
}
}
示例12: getUrl
public function getUrl()
{
return $this->_request->getUrl();
}
示例13: processSuccessfulRequest
/**
* @param Request $request
* @param string $body
*/
private function processSuccessfulRequest(Request $request, $body)
{
$response = $request->getResponse();
$headers = $request->getHeaders()->getAll();
$responseBody = $response->getBody(true);
$status = $response->getStatusCode();
$this->lastRequest['response']['body'] = $responseBody;
$this->lastRequest['response']['status'] = $status;
$this->logRequestSuccess($request->getMethod(), $request->getUrl(), $body, $headers, $status, $responseBody, $response->getInfo('total_time'));
}
示例14: signRequest
/**
* Adds "key" parameters as a Query Parameter
*
* @param Request $request
*/
protected function signRequest($request)
{
$url = $request->getUrl(true);
$url->getQuery()->add('key', $this->key);
$request->setUrl($url);
}
示例15: testCanRetrieveUrlObject
/**
* @covers Guzzle\Http\Message\Request
*/
public function testCanRetrieveUrlObject()
{
$request = new Request('GET', 'http://www.example.com/foo?abc=d');
$this->assertInstanceOf('Guzzle\\Http\\Url', $request->getUrl(true));
$this->assertEquals('http://www.example.com/foo?abc=d', $request->getUrl());
$this->assertEquals('http://www.example.com/foo?abc=d', (string) $request->getUrl(true));
}