File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change 55class 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+ }
You can’t perform that action at this time.
0 commit comments