yii2-httpclient icon indicating copy to clipboard operation
yii2-httpclient copied to clipboard

Missing info in documentation

Open rackycz opened this issue 1 year ago • 2 comments
trafficstars

What steps will reproduce the problem?

Open https://github.com/yiisoft/yii2-httpclient/blob/master/docs/guide/basic-usage.md

What's expected?

Working examples for content-type: application/json

What do you get instead?

Not working examples

Additional info

You cannot just use ->addHeaders(['content-type' => 'application/json']) or ->setHeaders(['content-type' => 'application/json']) to enable this content-type. You mainly need to set the format $request->setFormat(Client::FORMAT_JSON) otherwise content-type application/x-www-form-urlencoded will be forced thanks to the defaultFormat Client::FORMAT_URLENCODED

Q A
Yii version 2.0.50
Yii HTTP Client version ^2.0@dev
PHP version 7.4.33
Operating system Debian GNU/Linux 11 (bullseye)

rackycz avatar May 22 '24 12:05 rackycz

Good catch. Do you have some time for a pull request?

samdark avatar May 22 '24 12:05 samdark

I am not sure this is true. I just ran the following test with setHeaders and addHeaders and both works as described. I am running on PHP 8.3 though which has JSON included in core.

cgsmith avatar Sep 25 '24 18:09 cgsmith