Closed RootProgger closed 7 years ago
You are totally right. I will fix that asap.
Until than you can use a workaround to set headers by the deprecated approach (using headers
directly on root hierarchy of client.
Example:
guzzle:
clients:
test:
base_url: "testurl"
## START: DEPRECATED BUT WORKING APPROACH
headers:
Content-Type: "application/x-www-form-urlencoded; charset=utf-8"
## END: DEPRECATED BUT WORKING APPROACH
options:
auth:
- "username"
- "passwort"
verify: false
debug: true
I try that too but that also doesn't work. Only when i set the Content-Type in Post-Call it work.
I've tried it again and it works for me by using following code: config.yml:
guzzle:
logging: true
clients:
httpbin:
base_url: "https://httpbin.org"
headers:
Content-Type: "application/x-www-form-urlencoded; charset=utf-8"
options:
verify: false
debug: true
Controller:
public function indexAction(Request $request)
{
$client = $this->get('guzzle.client.httpbin');
$params = ['form_params'=> ['test' => 'aha']];
$response = $client->post('/post', $params);
$body = $response->getBody()->getContents();
var_dump($body);
Output Request:
I used dev-master which is similar to latest stable version 5.2.1.
Look at your Content-Type in Request, there's no charset only type
You are right. Didn't saw that, sorry.
Unfortunately this is something that comes from Guzzle Client. By using form_params
this header will be overridden by Guzzle: https://github.com/guzzle/guzzle/blob/master/src/Client.php#L303
So without using form_params
everything works like expected (except using headers in options, which is still a bug).
I created a new ticket regarding the override of content-type to split these two "bugs": https://github.com/8p/GuzzleBundle/issues/84
Released v5.2.2, fix: headers in options https://github.com/8p/GuzzleBundle/releases/tag/v5.2.2
Issue with form_params and content-type will be continued in #84
i try to setup a handler in config.yml, but the "Content-Type" doesn't work in request. config.yml:
Now when i call:
the charset is not set. But when i set the headers in post-call:
The Charset is correct set