1
0
Fork 0

Use curl for getDataFromHTTP utility function

master
Anonymous Contributor 2023-09-11 08:01:12 +02:00
parent 8231fbb08c
commit 939f600b3f
1 changed files with 12 additions and 9 deletions

View File

@ -42,17 +42,20 @@ class Util
return $res;
}
public static function getDataFromHTTP($url, $content = "", $requestTyp = "application/text")
public static function getDataFromHTTP($url, $content = "", $requestType = "application/text")
{
try {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 1);
if ($content != "") {
return file_get_contents($url, true, stream_context_create(array('http' => array('header' => 'Content-type: '.$requestTyp, 'method' => 'POST', 'timeout' => 0.5, 'content' => $content))));
} else {
return file_get_contents($url);
}
} catch (Exception $e) {
echo "(HTTP REQUEST) error while conntect to remote server. : ".$url;
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_USERAGENT, 'mcp/0.0.1');
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type' => $requestType
]);
}
return curl_exec($curl);
}
public static function sendInworldIM($fromUUID, $toUUID, $fromName, $targetURL, $text)