ImplDiscordAPI.java 文件源码

java
阅读 18 收藏 0 点赞 0 评论 0

项目:Javacord 作者:
/**
 * Requests the gateway.
 *
 * @return The requested gateway.
 */
public String requestGatewayBlocking() {
    try {
        logger.debug("Requesting gateway (token: {})", token.replaceAll(".{10}", "**********"));
        HttpResponse<JsonNode> response = Unirest.get("https://discordapp.com/api/v6/gateway")
                .header("authorization", token)
                .asJson();
        if (response.getStatus() == 401) {
            throw new IllegalStateException("Cannot request gateway! Invalid token?");
        }
        if (response.getStatus() < 200 || response.getStatus() > 299) {
            throw new IllegalStateException("Received http status code " + response.getStatus()
                    + " with message " + response.getStatusText() + " and body " + response.getBody());
        }
        String gateway = response.getBody().getObject().getString("url");
        logger.debug("Requested gateway {} (token: {})", gateway, token.replaceAll(".{10}", "**********"));
        return gateway;
    } catch (UnirestException e) {
        e.printStackTrace();
        return null;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号