-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpClient.php
39 lines (33 loc) · 954 Bytes
/
httpClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
$curl = curl_init();
$headers = [
"Cache-Control: no-cache",
"Content-Type: application/JSON"
];
if (!empty($customHeaders)) {
$headers = array_merge($customHeaders, $headers);
}
curl_setopt_array(
$curl,
[
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers
]
);
if (!empty($postMessage)) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $postMessage);
}
$response = curl_exec($curl);
$error = curl_error($curl);
curl_close($curl);
if ($error) {
file_put_contents($logErrorFile, date('Y-m-d h:i:s') . ' error: ' . $error . PHP_EOL, FILE_APPEND);
} else {
file_put_contents($logSuccessFile, date('Y-m-d h:i:s') . ' response: ' . $response . PHP_EOL, FILE_APPEND);
}