本文整理汇总了PHP中Guzzle\Http\Message\Request::send方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::send方法的具体用法?PHP Request::send怎么用?PHP Request::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doHealthCheck
/**
* Actual health check logic.
*
* @param HealthBuilder $builder
*
* @throws \Exception any Exception that should create a Status::DOWN
* system status.
*/
protected function doHealthCheck(HealthBuilder $builder)
{
/** @var Response $response */
$response = $this->request->send();
$builder->withDetail('statusCode', $response->getStatusCode());
if (!$response->isSuccessful()) {
$builder->down()->withDetail('body', $response->getBody(true));
return;
}
$builder->up();
}
示例2: proceedResponse
/**
* @param Request $request
* @return array|null
* @throws BadResponseException
* @throws FormatException
*/
protected function proceedResponse(Request $request)
{
try {
$response = $request->send();
} catch (ClientErrorResponseException $e) {
$response = $e->getResponse();
}
$body = $response->getBody(true);
if (empty($body) && $response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
return null;
}
$result = json_decode($body, true);
if ($result === null) {
# When response is just a sting.
$result = $body;
}
if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
return $result;
}
if (!$result || !$result['error']) {
throw new FormatException('Not valid error response', 3, null, $request, $response);
}
$message = $result['error']['message'];
$code = $result['error']['code'];
if ($response->getStatusCode() == 429) {
throw new RateLimitException($message, $code, null, $request, $response);
}
$e = new BadResponseException($message, $code, null, $request, $response);
$e->setError($result['error']);
throw $e;
}
示例3: resolveRequest
private function resolveRequest(\Guzzle\Http\Message\Request $request)
{
try {
$this->lastResponse = $request->send();
} catch (\Guzzle\Http\Exception\TooManyRedirectsException $tooManyRedirectsException) {
if ($this->hasRequestHistory($request)) {
$this->lastResponse = $this->getRequestHistory($request)->getLastResponse();
} else {
return $request->getUrl();
}
} catch (\Guzzle\Http\Exception\BadResponseException $badResponseException) {
if ($this->getConfiguration()->getRetryWithUrlEncodingDisabled() && !$this->getConfiguration()->getHasRetriedWithUrlEncodingDisabled()) {
$this->getConfiguration()->setHasRetriedWithUrlEncodingDisabled(true);
return $this->resolveRequest($this->deEncodeRequestUrl($request));
} else {
$this->lastResponse = $badResponseException->getResponse();
}
}
if ($this->getConfiguration()->getHasRetriedWithUrlEncodingDisabled()) {
$this->getConfiguration()->setHasRetriedWithUrlEncodingDisabled(false);
}
if ($this->getConfiguration()->getFollowMetaRedirects()) {
$metaRedirectUrl = $this->getMetaRedirectUrlFromLastResponse();
if (!is_null($metaRedirectUrl) && !$this->isLastResponseUrl($metaRedirectUrl)) {
return $this->resolve($metaRedirectUrl);
}
}
return $this->lastResponse->getEffectiveUrl();
}
示例4: 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();
}
return $this->app->make('trucker.response')->newInstance($this->app, $response);
}
示例5: request
public function request(Request $request)
{
try {
$response = $request->send();
} catch (\Exception $e) {
throw new ApiException($e->getMessage(), $e->getCode(), $e);
}
$apiResponse = new ApiResponse($response->getBody(), $response->getStatusCode(), $response->getContentType());
return $apiResponse;
}
示例6: send
public function send()
{
try {
return parent::send();
} catch (BadResponseException $e) {
$response = $e->getResponse();
$data = json_decode($response->getBody());
throw new GroongaException($data[0][3]);
}
}
示例7: testMagicOperationsReturnResult
/**
* Executing service description defined operations returns the result
* @group unit
*/
public function testMagicOperationsReturnResult()
{
$responseData = array("this" => "that");
Phockito::when($this->mockResponse->getStatusCode())->return(200);
Phockito::when($this->mockResponse->json())->return($this->testDescription);
Phockito::when($this->mockRequest->send())->return($this->mockResponse);
Phockito::when($this->client)->get(anything())->return($this->mockRequest);
Phockito::when($this->client)->callParent(anything(), anything())->return($responseData);
$result = $this->client->SomeOperation(array());
$this->assertEquals($result, $responseData);
}
示例8: testRequestThrowsExceptionOnBadResponse
/**
* @covers Guzzle\Http\Message\Request::getResponse
* @covers Guzzle\Http\Message\Request::processResponse
* @covers Guzzle\Http\Message\Request::getResponseBody
*/
public function testRequestThrowsExceptionOnBadResponse()
{
try {
$this->request->setResponse(new Response(404, array('Content-Length' => 3), 'abc'), true);
$this->request->send();
$this->fail('Expected exception not thrown');
} catch (BadResponseException $e) {
$this->assertInstanceOf('Guzzle\\Http\\Message\\RequestInterface', $e->getRequest());
$this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $e->getResponse());
$this->assertContains('Client error response', $e->getMessage());
}
}
示例9: loadSource
/**
* Load request sources
*
* @param $source
* @return Export
*/
public function loadSource($source = '')
{
empty($source) === false ? $this->setSource($source) : null;
$client = new Client($this->source, $this->options);
$this->request = $client->createRequest();
try {
$this->response = $this->request->send();
} catch (ResponseException $e) {
throw new BadResponseException($e->getMessage(), $e->getCode());
}
return $this;
}
示例10: 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);
}
示例11: send
/**
* @return \Sokil\Rest\Client\Response
*/
public function send()
{
try {
// disbatch beforeSend event
$this->_request->getEventDispatcher()->dispatch('onBeforeSend', new \Guzzle\Common\Event(array('request' => $this)));
// create response
$this->_response = new Response($this->_request->send(), $this->_structureClassName);
// trigger event
$this->_request->getEventDispatcher()->dispatch('onParseResponse', new \Guzzle\Common\Event(array('request' => $this, 'response' => $this->_response)));
// log
if ($this->hasLogger()) {
$this->getLogger()->debug((string) $this->_request . PHP_EOL . (string) $this->_request->getResponse());
}
return $this->_response;
} catch (\Exception $e) {
if ($this->hasLogger()) {
$this->getLogger()->debug((string) $e);
}
throw $e;
}
}
示例12: iRequest
/**
* @When /^I request "(GET|PUT|POST|DELETE|PATCH) ([^"]*)"$/
*/
public function iRequest($httpMethod, $resource)
{
// process any %battles.last.id% syntaxes
$resource = $this->processReplacements($resource);
$this->resource = $resource;
// reset the response payload
$this->responsePayload = null;
$method = strtolower($httpMethod);
try {
switch ($httpMethod) {
case 'PUT':
case 'POST':
case 'PATCH':
// process any %user.weaverryan.id% syntaxes
$payload = $this->processReplacements($this->requestPayload);
$this->lastRequest = $this->client->{$method}($resource, null, $payload);
break;
default:
$this->lastRequest = $this->client->{$method}($resource);
}
if ($this->authUser) {
$this->lastRequest->setAuth($this->authUser, $this->authPassword);
}
foreach ($this->headers as $key => $val) {
$this->lastRequest->setHeader($key, $val);
}
$this->response = $this->lastRequest->send();
} catch (BadResponseException $e) {
$response = $e->getResponse();
// Sometimes the request will fail, at which point we have
// no response at all. Let Guzzle give an error here, it's
// pretty self-explanatory.
if ($response === null) {
throw $e;
}
$this->response = $e->getResponse();
}
}
示例13: send
/**
* @param \Guzzle\Http\Message\Request $request
* @return \Guzzle\Http\Message\Response
*/
public function send(\Guzzle\Http\Message\Request $request)
{
$token = $this->getToken();
$request->setHeader('X-Auth-Token', $token['token'])->setHeader('Content-Type', 'application/json')->setHeader('X-Auth-UserId', $token['user_id']);
return $request->send();
}
示例14: post
/**
* @param string $uri
* @param array $headers
* @param string $postBody
* @param array $options
* @return array|\Guzzle\Http\Message\Response
*/
public function post($uri, $headers = [], $postBody = null, $options = [])
{
$this->request = $this->client->post($uri, $headers, $postBody, $options);
$this->response = $this->request->send();
return $this->response;
}
示例15: getResponse
/**
* Get the response from the prepared request.
*
* @param \Guzzle\Http\Message\Request $request
*
* @return array
*/
protected function getResponse($request)
{
try {
$response = json_decode($request->send()->getBody(), true);
return $response['response'];
} catch (BadResponseException $bre) {
return;
}
}