M
M
Mark2020-09-19 03:00:08
Yii
Mark, 2020-09-19 03:00:08

How to solve the problem of duplicate response body by Yii HTTP Client?

The problem is with one API method, which is responsible for the delivery to order.
The object must be:

{"tid":4828,"dcid":{"x":482222},"paid":true,"error":[]}


But for some reason Yii2 duplicates it, it turns out:
{"tid":4828,"dcid":{"x":482222},"paid":true,"error":[]}{ "tid": 4828, "dcid": { "x": 482222 }, "paid": true, "error": [] }


Initially I thought about the API, but I tried the same request in Postman - there is a valid format.

The code is pretty simple:
$response= $client->createRequest()
            ->setUrl(self::API_ENDPOINT . "$collection/$method")
            ->setMethod("POST")
            ->setData($params)
            ->addHeaders(['Token' => $this->apiKey])->send();


If you try to access $response->data HTTP Client will throw a "Syntax error" exception, which is actually true - this format is invalid. If through $response->getContent() we get this double.

Who faced the problem, how to solve?

Request Object: https://pastebin.com/kU0kPWnQ
Response Object: https://pastebin.com/WCgEik1p

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question