$this->baseUri, ]); if (isset($this->key)) { unset($headers['authorization']); $headers['Authorization'] = $this->key; } $response = $client->request($method, $requestUrl, ['json' => $body, 'form_params' => $formParams, 'headers' => $headers]); return $response->getBody()->getContents(); } public function perfomRequestWithFiles($method, $requestUrl, $body = [], $headers = [], $formParams = []) { if (isset($this->key)) { unset($headers['authorization']); $headers['Authorization'] = $this->key; } $client = new Client([ 'base_uri' => $this->baseUri, 'headers' => $headers ]); $request = new Request($method, $requestUrl, [], new MultipartStream($this->bodyToMultipart($body))); $response = $client->send($request); return $response->getBody()->getContents(); } private function bodyToMultipart(array $body) { $multipart = []; foreach ($body as $key => $value) { if ($value instanceof UploadedFile) { array_push($multipart, [ 'name' => $key, 'contents' => file_get_contents($value->getRealPath()), 'mine-type' => $value->getMimeType(), 'filename' => $value->getClientOriginalName(), // 'headers' => [ 'Content-type' => 'application/octet-stream'] // 'Content-type' => 'multipart/form-data', ]); } else { array_push($multipart, [ 'name' => $key, 'contents' => $value, ]); } } return $multipart; } }