Goutte icon indicating copy to clipboard operation
Goutte copied to clipboard

Use User-Agent header from Guzzle client

Open 4n70w4 opened this issue 5 years ago • 7 comments

Guzzle code:

$base_uri = 'https://google.com/';

$headers = [
        'User-Agent' => $useragent,
];

$transport= new Client(['base_uri' => $base_uri, RequestOptions::HEADERS => $headers]);

$transport->request('GET', 'http://webhook.site/afb7fc90-9666-4e39-947c-35fb11646755');

Goutte code:

$client = new \Goutte\Client();
$client->setClient($transport);

$client->request('GET', 'http://webhook.site/afb7fc90-9666-4e39-947c-35fb11646755');

Guzzle result:

host: webhook.site
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36

Goutte result:

host: google.com
user-agent: Symfony BrowserKit
  • Don't used Guzzle user-agent header.
  • Incorrect host header.

4n70w4 avatar Jun 21 '19 13:06 4n70w4

same problem, goutte is ignoring the guzzle client completely (ignores the cookie jar as well)

bilalghouri avatar Dec 05 '19 21:12 bilalghouri

try:

new \GuzzleHttp\Client(['headers' => ['User-Agent' => null]]);

sunnysideup avatar Dec 17 '19 04:12 sunnysideup

see: https://github.com/guzzle/guzzle/issues/894

sunnysideup avatar Dec 17 '19 04:12 sunnysideup

@sunnysideup what for?

4n70w4 avatar Dec 17 '19 09:12 4n70w4

Ignore my comments, I thought it was helpful, but perhaps it is not.

sunnysideup avatar Dec 17 '19 09:12 sunnysideup

@4n70w4 @bilalghouri Hey! Did you find a solution?

It's 2020, but I have same problem with "guzzlehttp/guzzle": "^6.3", and "fabpot/goutte": "^3.2",. I know that there is goutte v.4 available now, but it uses symfony httpClient, but it's new and there's no time for refactoring my code unfortunately..

gadnis avatar Sep 24 '20 20:09 gadnis

try: $transport= new Client(['HTTP_USER_AGENT' => 'Mozilla/5.0]);

bavial avatar Mar 13 '21 21:03 bavial