Skip to content

Commit 3aca224

Browse files
committed
Update CurlRequest.php
1 parent 79bd341 commit 3aca224

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/CurlRequest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,24 @@ public function prepareSend(): CurlRequest
5353
$ch = $this->getCh();
5454
$method = $this->getMethod();
5555
$uri = $this->getUri();
56-
// $headers = $this->getHeadersLines();
57-
$body = 'GET' === $method ? $this->getQuery() : (
58-
'POST' === $method
59-
? json_encode($this->getPost())
60-
: $this->getBody()
61-
);
56+
6257
// добавляем данные запроса
6358
if ('GET' === $method) {
59+
$body = $this->getQuery();
6460
$uri .= static::prepareDataToUriQuery($body);
6561
} else {
62+
$type = $this->getHeader('Content-Type');
63+
if (false !== strpos($type, 'application/json')) {
64+
$this->withBodyJson($this->getBody());
65+
}
66+
$body = $this->getBody();
67+
6668
if ('POST' === $method) curl_setopt($ch, CURLOPT_POST, 1);
6769
else curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
6870
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
6971
$this->withHeader('Content-Length', mb_strlen($body));
7072
}
73+
7174
// устанавливаем cookie
7275
if (!empty($this->cookies)) {
7376
$cookies = [];

0 commit comments

Comments
 (0)