setHeaders($headers); $cli->set($set == [] ? ['timeout' => 15.0] : $set); $cli->get($parse["path"] . (isset($parse["query"]) ? "?" . $parse["query"] : "")); if ($return_body) { if ($cli->errCode != 0 || $cli->statusCode != 200) return false; $a = $cli->body; $cli->close(); return $a; } else { $cli->close(); return $cli; } } /** * 使用Swoole协程客户端发起HTTP POST请求 * 返回请求后的body * 如果请求失败或返回状态不是200,则返回 false * @param $url * @param array $header * @param $data * @param array $set * @param bool $return_body * @return bool|string|Client */ public static function post($url, array $header, $data, $set = [], $return_body = true) { $parse = parse_url($url); if (!isset($parse["host"])) { Console::warning("ZMRequest: url must contains scheme such as \"http(s)://\""); return false; } $port = $parse["port"] ?? (($parse["scheme"] ?? "http") == "https" ? 443 : 80); $cli = new Client($parse["host"], $port, (($parse["scheme"] ?? "http") == "https" ? true : false)); $cli->set($set == [] ? ['timeout' => 15.0] : $set); $cli->setHeaders($header); $cli->post($parse["path"] . (isset($parse["query"]) ? ("?" . $parse["query"]) : ""), $data); if ($return_body) { if ($cli->errCode != 0 || $cli->statusCode != 200) return false; $a = $cli->body; $cli->close(); return $a; } else { $cli->close(); return $cli; } } /** * @param $url * @param array $set * @param array $header * @return ZMWebSocket * @since 1.5 */ public static function websocket($url, $set = ['websocket_mask' => true], $header = []) { return new ZMWebSocket($url, $set, $header); } /** * @param $option * @return Saber */ public static function session($option) { return Saber::session($option); } }