-
Notifications
You must be signed in to change notification settings - Fork 1k
Goutte not using httpclient headers #401
Comments
You can set the header in this manner: I'm trying to set the CURL options, hoping someone can help me. All the links for doing this are old. |
Thanks for your answer. When I set headers in the way you suggested me I have this error:
|
As the BrowserKit will override user-agent header during executing, you have to use setServerParameter() to put user agent header back.
|
Thank you for that important/critical piece of information, much appreciated! |
@kiang, that's the correct answer, just tested, thanks for your great help! |
Is this new? I have multiple scripts in which
has worked flawlessly. |
Yup. There it is: |
Yes, this answer is correct (#401 (comment)), I tested it on an updated version of Goutte. |
I didn't read the comments thoroughly enough the first time through but This Comment is spot on. I found it after digging through the code with trial and error. This: Sets the user agent properly and solved my issue with a site. |
This works in the current implementation:
Have a look at the constructor of Symfony\Component\BrowserKit\AbstractBrowser which calls the method setServerParameters(). The Goutte class Client is indirectly derived from Symfony\Component\BrowserKit\AbstractBrowser |
can you explain how to do this? when I copy the code it just shows errors and says must be of type HttpClientInterface |
Hi!
I'm trying to edit the User-Agent as described at The HttpClient Component Documentation but the crawler always use 'Symfony BrowserKit'. I'm doing something wrong or is a bug?
$client = new Client(HttpClient::create(['timeout' => 5000, 'headers' => ['User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36']]));
Thanks for your help.
The text was updated successfully, but these errors were encountered: