pocketmine\utils\Utils::postURL PHP Method

postURL() public static method

POSTs data to an URL
public static postURL ( $page, array | string $args, integer $timeout = 10, array $extraHeaders = [] ) : boolean | mixed
$page
$args array | string
$timeout integer
$extraHeaders array
return boolean | mixed
    public static function postURL($page, $args, $timeout = 10, array $extraHeaders = [])
    {
        if (Utils::$online === false) {
            return false;
        }
        $ch = curl_init($page);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge(["User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 PocketMine-MP"], $extraHeaders));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int) $timeout);
        curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout);
        $ret = curl_exec($ch);
        curl_close($ch);
        return $ret;
    }

Usage Example

 public function onRun()
 {
     try {
         Utils::postURL($this->endpoint, $this->data, 5, ["Content-Type: application/json", "Content-Length: " . strlen($this->data)]);
     } catch (\Exception $e) {
     }
 }
All Usage Examples Of pocketmine\utils\Utils::postURL