本文整理汇总了PHP中Guzzle\Http\Message\Request::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getResponse方法的具体用法?PHP Request::getResponse怎么用?PHP Request::getResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::getResponse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetManualResponse
public function testSetManualResponse()
{
$response = new Response(200, array('Date' => 'Sat, 16 Oct 2010 17:27:14 GMT', 'Expires' => '-1', 'Cache-Control' => 'private, max-age=0', 'Content-Type' => 'text/html; charset=ISO-8859-1'), 'response body');
$this->assertSame($this->request, $this->request->setResponse($response), '-> setResponse() must use a fluent interface');
$this->assertEquals('complete', $this->request->getState(), '-> setResponse() must change the state of the request to complete');
$this->assertSame($response, $this->request->getResponse(), '-> setResponse() must set the exact same response that was passed in to it');
}
示例2: sendRequest
public function sendRequest()
{
$client = new Client();
// make a request object
$request = $client->createRequest($this->requestType, $this->host . $this->resource);
// set headers
foreach ($this->headers as $header => $value) {
$request->setHeader($header, $value);
}
// set body
if (!empty($this->body)) {
$request->setBody($this->body);
}
$this->request = $request;
try {
// finally send the request
$this->response = $request->send();
} catch (\Exception $e) {
$this->response = $this->request->getResponse();
}
}
示例3: send
/**
* Send the request
*/
public function send()
{
// make a request object
$this->request = $this->client->createRequest($this->method, $this->host . $this->resource);
// set headers
foreach ($this->headers as $header => $value) {
$this->request->setHeader($header, $value);
}
// set body
if (!empty($this->body)) {
$this->request->setBody($this->body);
}
try {
// finally send the request
$this->response = $this->client->send($this->request);
} catch (BadResponseException $e) {
$this->response = $this->request->getResponse();
}
$this->sent = true;
}
示例4: getRawResponse
/**
*
* @return \Guzzle\Http\Message\Response
*/
public function getRawResponse()
{
return $this->_request->getResponse();
}
示例5: 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'));
}
示例6: testReceivingShortStatusLineResponse
/**
* Many RESTful frameworks omit the text status from the header. That
* provides a response like "HTTP/1.1 200". Prevent an Undefined offset
* by checking to see how many parts of the status line are provided
* before trying to assign them.
*
* @covers Guzzle\Http\Message\Request::receiveResponseHeader
*/
public function testReceivingShortStatusLineResponse()
{
$request = new Request('GET', $this->getServer()->getUrl());
$request->receiveResponseHeader('HTTP/1.1 200');
$this->assertSame(200, $request->getResponse()->getStatusCode());
$this->assertSame('OK', $request->getResponse()->getReasonPhrase());
}
示例7: testReceivingUnsuccessfulResponseUsesOtherResponseBody
/**
* Users sometimes want to use a custom stream when receiving a response body.
* Because of the various potential for retrying failed requests, the stream
* specified by the user should only be written to in the event that a
* successful response was received. Otherwise, a new temp stream is created
* to store the body of the failed request.
*
* @covers Guzzle\Http\Message\Request::receiveResponseHeader
*/
public function testReceivingUnsuccessfulResponseUsesOtherResponseBody()
{
$request = new Request('GET', $this->getServer()->getUrl());
$body = EntityBody::factory();
$request->setResponseBody($body);
$request->receiveResponseHeader('HTTP/1.1 503 Service Unavailable');
$this->assertNotSame($body, $request->getResponse()->getBody());
}
示例8: testDoesNotInjectUnsatisfiableResponsesOnException
/**
* @dataProvider unsatisfiableOnErrorProvider
*/
public function testDoesNotInjectUnsatisfiableResponsesOnException($requestCanCache, $requestHeaders, $responseParts)
{
$storage = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\CacheStorageInterface')->setMethods(array('fetch'))->getMockForAbstractClass();
$storage->expects($this->exactly($requestCanCache ? 2 : 0))->method('fetch')->will($this->returnValue($responseParts));
$plugin = new CachePlugin(array('storage' => $storage));
$request = new Request('GET', 'http://foo.com', $requestHeaders);
$plugin->onRequestBeforeSend(new Event(array('request' => $request)));
$plugin->onRequestException($event = new Event(array('request' => $request, 'response' => $response = $request->getResponse(), 'exception' => $this->getMock('Guzzle\\Http\\Exception\\CurlException'))));
$this->assertSame($response, $request->getResponse());
}
示例9: testInjectsSatisfiableResponses
public function testInjectsSatisfiableResponses()
{
$storage = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\CacheStorageInterface')->setMethods(array('fetch'))->getMockForAbstractClass();
$storage->expects($this->once())->method('fetch')->will($this->returnValue(array(200, array(), 'foo')));
$plugin = new CachePlugin(array('storage' => $storage));
$request = new Request('GET', 'http://foo.com');
$plugin->onRequestBeforeSend(new Event(array('request' => $request)));
$this->assertEquals(200, $request->getResponse()->getStatusCode());
$this->assertEquals('foo', $request->getResponse()->getBody(true));
$this->assertContains('key=', (string) $request->getResponse()->getHeader('X-Guzzle-Cache'));
$this->assertTrue($request->getResponse()->hasHeader('Age'));
}