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; 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 != "") { 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)))); curl_setopt($curl, CURLOPT_POST, true);
} else { curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
return file_get_contents($url); curl_setopt($curl, CURLOPT_USERAGENT, 'mcp/0.0.1');
} curl_setopt($curl, CURLOPT_HTTPHEADER, [
} catch (Exception $e) { 'Content-Type' => $requestType
echo "(HTTP REQUEST) error while conntect to remote server. : ".$url; ]);
} }
return curl_exec($curl);
} }
public static function sendInworldIM($fromUUID, $toUUID, $fromName, $targetURL, $text) public static function sendInworldIM($fromUUID, $toUUID, $fromName, $targetURL, $text)