/** * @return GoutteClient */ protected function getWebClient() { if (!$this->client) { $this->client = new GoutteClient(); $this->client->setServerParameter('HTTP_USER_AGENT', 'Crawler'); } return $this->client; }
/** * @return Client */ public function createClient() { $client = new Client(); $client->setServerParameter('HTTP_HOST', $this->host); return $client; }
public function testPostMultipartFormWithoutFiles() { $guzzle = $this->getGuzzle(); $client = new Client(); $client->setClient($guzzle); $params = array('foo' => 'bar'); $client->setServerParameter('Content-Type', 'multipart/form-data'); $client->request('POST', 'http://www.example.com/', $params); /* * @var Request */ $request = end($this->history)['request']; $stream = $request->getBody(); $boundary = $stream->getBoundary(); $this->assertEquals("--{$boundary}\r\nContent-Disposition: form-data; name=\"foo\"\r\nContent-Length: 3\r\n" . "\r\nbar\r\n" . "--{$boundary}--\r\n", $stream->getContents()); }
/** * Used internally to create/get the HTTP client * * @return Goutte\Client */ private function getBrowser() { if (!$this->browser instanceof Client) { $browser = new Client(); $browser->setServerParameter('HTTP_USER_AGENT', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)'); $this->browser = $browser; } return $this->browser; }