本文整理汇总了PHP中Guzzle\Http\Client::getDefaultUserAgent方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getDefaultUserAgent方法的具体用法?PHP Client::getDefaultUserAgent怎么用?PHP Client::getDefaultUserAgent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::getDefaultUserAgent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRequestCanBeSentUsingCurl
/**
* This test launches a dummy Guzzle\Http\Server\Server object that listens
* for incoming requests. The server allows us to test how cURL sends
* requests and receives responses. We can validate the request structure
* and whether or not the response was interpreted correctly.
*
* @covers Guzzle\Http\Message\Request
*/
public function testRequestCanBeSentUsingCurl()
{
$this->getServer()->flush();
$this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length: 4\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\nConnection: close\r\n\r\ndata", "HTTP/1.1 200 OK\r\nContent-Length: 4\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\nConnection: close\r\n\r\ndata", "HTTP/1.1 404 Not Found\r\nContent-Encoding: application/xml\r\nContent-Length: 48\r\n\r\n<error><mesage>File not found</message></error>"));
$request = RequestFactory::getInstance()->create('GET', $this->getServer()->getUrl());
$request->setClient($this->client);
$response = $request->send();
$this->assertEquals('data', $response->getBody(true));
$this->assertEquals(200, (int) $response->getStatusCode());
$this->assertEquals('OK', $response->getReasonPhrase());
$this->assertEquals(4, $response->getContentLength());
$this->assertEquals('Thu, 01 Dec 1994 16:00:00 GMT', $response->getExpires());
// Test that the same handle can be sent twice without setting state to new
$response2 = $request->send();
$this->assertNotSame($response, $response2);
try {
$request = RequestFactory::getInstance()->create('GET', $this->getServer()->getUrl() . 'index.html');
$request->setClient($this->client);
$response = $request->send();
$this->fail('Request did not receive a 404 response');
} catch (BadResponseException $e) {
}
$requests = $this->getServer()->getReceivedRequests(true);
$messages = $this->getServer()->getReceivedRequests(false);
$port = $this->getServer()->getPort();
$userAgent = $this->client->getDefaultUserAgent();
$this->assertEquals('127.0.0.1:' . $port, $requests[0]->getHeader('Host'));
$this->assertEquals('127.0.0.1:' . $port, $requests[1]->getHeader('Host'));
$this->assertEquals('127.0.0.1:' . $port, $requests[2]->getHeader('Host'));
$this->assertEquals('/', $requests[0]->getPath());
$this->assertEquals('/', $requests[1]->getPath());
$this->assertEquals('/index.html', $requests[2]->getPath());
$parts = explode("\r\n", $messages[0]);
$this->assertEquals('GET / HTTP/1.1', $parts[0]);
$parts = explode("\r\n", $messages[1]);
$this->assertEquals('GET / HTTP/1.1', $parts[0]);
$parts = explode("\r\n", $messages[2]);
$this->assertEquals('GET /index.html HTTP/1.1', $parts[0]);
}
示例2: dataProvider
/**
* Data provider for factory tests
*
* @return array
*/
public function dataProvider()
{
$testFile = __DIR__ . '/../../../../../phpunit.xml.dist';
$postBody = new QueryString(array('file' => '@' . $testFile));
$qs = new QueryString(array('x' => 'y', 'z' => 'a'));
$client = new Client();
$userAgent = $client->getDefaultUserAgent();
$auth = base64_encode('michael:123');
$testFileSize = filesize($testFile);
$tests = array(array('GET', 'http://www.google.com/', null, null, array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_WRITEFUNCTION => 'callback', CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_HTTPHEADER => array('Accept:', 'Host: www.google.com', 'User-Agent: ' . $userAgent))), array('TRACE', 'http://www.google.com/', null, null, array(CURLOPT_CUSTOMREQUEST => 'TRACE')), array('GET', 'http://127.0.0.1:8080', null, null, array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_WRITEFUNCTION => 'callback', CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_PORT => 8080, CURLOPT_HTTPHEADER => array('Accept:', 'Host: 127.0.0.1:8080', 'User-Agent: ' . $userAgent))), array('HEAD', 'http://www.google.com/', null, null, array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_HTTPHEADER => array('Accept:', 'Host: www.google.com', 'User-Agent: ' . $userAgent), CURLOPT_NOBODY => 1)), array('GET', 'https://michael:123@localhost/index.html?q=2', null, null, array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_WRITEFUNCTION => 'callback', CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_HTTPHEADER => array('Accept:', 'Host: localhost', 'Authorization: Basic ' . $auth, 'User-Agent: ' . $userAgent), CURLOPT_PORT => 443)), array('GET', 'http://localhost:8124/', array('x-test-data' => 'Guzzle'), null, array(CURLOPT_PORT => 8124, CURLOPT_HTTPHEADER => array('Accept:', 'Host: localhost:8124', 'x-test-data: Guzzle', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', 'x-test-data' => 'Guzzle')), array('POST', 'http://localhost:8124/post.php', null, $qs, array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_WRITEFUNCTION => 'callback', CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_POSTFIELDS => 'x=y&z=a', CURLOPT_HTTPHEADER => array('Expect:', 'Accept:', 'Host: localhost:8124', 'Content-Type: application/x-www-form-urlencoded; charset=utf-8', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', 'Content-Length' => '7', '!Expect' => null, 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8', '!Transfer-Encoding' => null)), array('PUT', 'http://localhost:8124/put.php', null, EntityBody::factory(fopen($testFile, 'r+')), array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_WRITEFUNCTION => 'callback', CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_READFUNCTION => 'callback', CURLOPT_INFILESIZE => filesize($testFile), CURLOPT_HTTPHEADER => array('Expect:', 'Accept:', 'Host: localhost:8124', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', '!Expect' => null, 'Content-Length' => $testFileSize, '!Transfer-Encoding' => null)), array('POST', 'http://localhost:8124/post.php', null, array('x' => 'y', 'a' => 'b'), array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_WRITEFUNCTION => 'callback', CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_POST => 1, CURLOPT_POSTFIELDS => 'x=y&a=b', CURLOPT_HTTPHEADER => array('Expect:', 'Accept:', 'Host: localhost:8124', 'Content-Type: application/x-www-form-urlencoded; charset=utf-8', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', 'Content-Length' => '7', '!Expect' => null, 'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8', '!Transfer-Encoding' => null)), array('POST', 'http://localhost:8124/post.php', array('Content-Type' => 'application/json'), '{"hi":"there"}', array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_WRITEFUNCTION => 'callback', CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_UPLOAD => true, CURLOPT_INFILESIZE => 14, CURLOPT_HTTPHEADER => array('Expect:', 'Accept:', 'Host: localhost:8124', 'Content-Type: application/json', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', 'Content-Type' => 'application/json', '!Expect' => null, 'Content-Length' => '14', '!Transfer-Encoding' => null)), array('POST', 'http://localhost:8124/post.php', array('Content-Type' => 'application/json', 'Transfer-Encoding' => 'chunked'), '{"hi":"there"}', array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_WRITEFUNCTION => 'callback', CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_UPLOAD => true, CURLOPT_HTTPHEADER => array('Expect:', 'Accept:', 'Host: localhost:8124', 'Transfer-Encoding: chunked', 'Content-Type: application/json', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', 'Content-Type' => 'application/json', '!Expect' => null, 'Transfer-Encoding' => 'chunked', '!Content-Length' => '')), array('POST', 'http://localhost:8124/post.php', null, '', array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array('Expect:', 'Accept:', 'Host: localhost:8124', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', 'Content-Length' => '0', '!Transfer-Encoding' => null)), array('POST', 'http://localhost:8124/post.php', null, array(), array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array('Expect:', 'Accept:', 'Host: localhost:8124', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', 'Content-Length' => '0', '!Transfer-Encoding' => null)), array('PATCH', 'http://localhost:8124/patch.php', null, 'body', array(CURLOPT_INFILESIZE => 4, CURLOPT_HTTPHEADER => array('Expect:', 'Accept:', 'Host: localhost:8124', 'User-Agent: ' . $userAgent))), array('DELETE', 'http://localhost:8124/delete.php', null, 'body', array(CURLOPT_CUSTOMREQUEST => 'DELETE', CURLOPT_INFILESIZE => 4, CURLOPT_HTTPHEADER => array('Expect:', 'Accept:', 'Host: localhost:8124', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', 'Content-Length' => '4', '!Expect' => null, '!Transfer-Encoding' => null)));
$postTest = array('POST', 'http://localhost:8124/post.php', null, $postBody, array(CURLOPT_RETURNTRANSFER => 0, CURLOPT_HEADER => 0, CURLOPT_CONNECTTIMEOUT => 150, CURLOPT_WRITEFUNCTION => 'callback', CURLOPT_HEADERFUNCTION => 'callback', CURLOPT_POST => 1, CURLOPT_POSTFIELDS => array('file' => '@' . $testFile . ';filename=phpunit.xml.dist;type=application/octet-stream'), CURLOPT_HTTPHEADER => array('Accept:', 'Host: localhost:8124', 'Content-Type: multipart/form-data', 'Expect: 100-Continue', 'User-Agent: ' . $userAgent)), array('Host' => '*', 'User-Agent' => '*', 'Content-Length' => '*', 'Expect' => '100-Continue', 'Content-Type' => 'multipart/form-data; boundary=*', '!Transfer-Encoding' => null));
if (version_compare(phpversion(), '5.5.0', '>=')) {
$postTest[4][CURLOPT_POSTFIELDS] = array('file' => new \CurlFile($testFile, 'application/octet-stream', 'phpunit.xml.dist'));
}
$tests[] = $postTest;
return $tests;
}
示例3: getDefaultUserAgent
public function getDefaultUserAgent()
{
return 'Cometdocs/' . self::VERSION . ' ' . parent::getDefaultUserAgent();
}