-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
function doRequest($url, $authorizationBearerToken, $data = null){ | ||
Check notice on line 3 in Src/lib/request.php Codacy Production / Codacy Static Code AnalysisSrc/lib/request.php#L3
Check notice on line 3 in Src/lib/request.php Codacy Production / Codacy Static Code AnalysisSrc/lib/request.php#L3
Check notice on line 3 in Src/lib/request.php Codacy Production / Codacy Static Code AnalysisSrc/lib/request.php#L3
|
||
$headers = array(); | ||
$headers[] = "User-Agent: " . USER_AGENT; | ||
$headers[] = "Content-type: application/json"; | ||
$headers[] = "Authorization: Bearer " . $authorizationBearerToken; | ||
|
||
$fields = array( | ||
CURLOPT_URL => $url, | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_HEADER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 0, | ||
CURLOPT_FOLLOWLOCATION => true, | ||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
CURLOPT_SSL_VERIFYPEER => false, | ||
CURLOPT_SSL_VERIFYHOST => false, | ||
CURLOPT_HTTPHEADER => $headers | ||
); | ||
|
||
if ($data !== null) { | ||
$fields[CURLOPT_POST] = true; | ||
$fields[CURLOPT_POSTFIELDS] = json_encode($data); | ||
} | ||
|
||
$curl = curl_init(); | ||
|
||
curl_setopt_array($curl, $fields); | ||
|
||
$response = curl_exec($curl); | ||
|
||
if ($response === false) { | ||
echo htmlspecialchars($url); | ||
Check failure on line 35 in Src/lib/request.php Codacy Production / Codacy Static Code AnalysisSrc/lib/request.php#L35
|
||
echo "\r\n"; | ||
die(curl_error($curl)); | ||
} | ||
|
||
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); | ||
$header = substr($response, 0, $headerSize); | ||
$headers = extractHeaders($header); | ||
$body = substr($response, $headerSize); | ||
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||
curl_close($curl); | ||
|
||
return array("status" => $http_code, "headers" => $headers, "body" => $body); | ||
Check notice on line 47 in Src/lib/request.php Codacy Production / Codacy Static Code AnalysisSrc/lib/request.php#L47
|
||
} | ||