#Simple GET request taking wayy too long.

5 messages · Page 1 of 1 (latest)

random burrow
#

Does anyone know why a simple GET request to Discord's /user/{id} endpoint (this is also happening for all other requests, regardless of the endpoint) is taking up to 1000ms? My internet isn't bad and similar requests works fine on the default Discord client.

I'm using okhttp 4.11.0, though I have tried other HTTP libraries and none of them seem to be making much of a difference. Here's my code:

            String url = URLS.BASE_URL + this.url;
            OkHttpClient client = new OkHttpClient();

            Request.Builder requestBuilder = new Request.Builder().url(url);

            String s = body != null ? body.toString() : aBody.toString();
            RequestBody requestBody = null;

            if (contentType == null) {
                contentType = "application/json";
            }

            requestBody = RequestBody.create(MediaType.parse(contentType), s);

            switch (requestMethod) {
                case POST -> requestBuilder.post(requestBody);
                case PATCH -> requestBuilder.patch(requestBody);
                case PUT -> requestBuilder.put(requestBody);
                case DELETE -> requestBuilder.delete(requestBody);
                case GET -> requestBuilder.get();
                default -> requestBuilder.method(requestMethod.name(), requestBody);
            }

            requestBuilder.addHeader("User-Agent", "discord.jar (https://github.com/discord-jar/, 1.0.0)");
            if (auth) {
                requestBuilder.addHeader("Authorization", "Bot " + djv.getToken());
            }
            headers.forEach((key, value) -> requestBuilder.addHeader(key, value));

            Request request = requestBuilder.build();
            long start = System.currentTimeMillis();
            Response response = client.newCall(request).execute();
            long end = System.currentTimeMillis();
            System.out.println("Request took " + (end - start) + "ms");```
hasty cedarBOT
#

This post has been reserved for your question.

Hey @random burrow! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

hasty cedarBOT
#

<@&765578700724371486>

Requested by seailz#0001