Skip to content

Commit 480645e

Browse files
authored
Update HttpClient.php
1 parent 0d915a0 commit 480645e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Utils/HttpClient.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class HttpClient
66
{
77
private array $header;
8-
private ?string $payload;
8+
private string $payload = "";
99
private string $url;
1010
private string $method;
1111

@@ -37,14 +37,18 @@ public function fetch(): object
3737
{
3838
try {
3939
$curl = curl_init();
40-
41-
curl_setopt_array($curl, [
40+
$setopt_array = [
4241
CURLOPT_HTTPHEADER => $this->header,
43-
CURLOPT_POSTFIELDS => $this->payload,
4442
CURLOPT_URL => $this->url,
4543
CURLOPT_RETURNTRANSFER => true,
4644
CURLOPT_CUSTOMREQUEST => strtoupper($this->method),
47-
]);
45+
];
46+
47+
if (!empty($this->payload)) {
48+
$setopt_array[CURLOPT_POSTFIELDS] = $this->payload;
49+
}
50+
51+
curl_setopt_array($curl, $setopt_array);
4852

4953
$response = curl_exec($curl);
5054
curl_close($curl);
@@ -54,4 +58,4 @@ public function fetch(): object
5458
throw new \Exception("Curl request Failed. Reason: ". $e->getMessage());
5559
}
5660
}
57-
}
61+
}

0 commit comments

Comments
 (0)