API Mojang Request Error 307

Discussion in 'Plugin Development' started by Noctos, Jan 28, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    Noctos

    Hey ! I want to dev a ban plugin. And so I need to ban someone even he's offline. So, I have two choices : use the deprecated method : getOfflinePlayer(Username) or build a request POST to get the UUID of the player with the Mojang API. I chose the API so I tried to dev a request POST but the Sysout says : "
    Code:
    > [16:33:27] [Server thread/INFO]: <html>
    > [16:33:27] [Server thread/INFO]: <head><title>307 Temporary Redirect</title></head>
    > [16:33:27] [Server thread/INFO]: <body bgcolor="white">
    > [16:33:27] [Server thread/INFO]: <center><h1>307 Temporary Redirect</h1></center>
    > [16:33:27] [Server thread/INFO]: <hr><center>CloudFront</center>
    > [16:33:27] [Server thread/INFO]: </body>
    > [16:33:27] [Server thread/INFO]: </html>
    "

    I dont understand what I need to do in my code :
    Code:
    private void requestUUID(String string) throws ParseException, UnsupportedOperationException, IOException{
          
            HttpClient httpClient = HttpClientBuilder.create().build();
            try {
                HttpPost request = new HttpPost("http://api.mojang.com/profiles/minecraft");
                StringEntity params = new StringEntity("{\" " + string + "\"} ");
                request.addHeader("content-type", "application/json");
                request.setEntity(params);
                HttpResponse response = httpClient.execute(request);
                HttpEntity entity = response.getEntity();
                String responseString = EntityUtils.toString(entity, "UTF-8");
                System.out.println(responseString);
              
            } catch (Exception ex) {
            } finally {
                httpClient.getConnectionManager().shutdown();
            }
          
    }
    Could someone help me ?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Noctus and why not just store a list of names? Or use the deprecated method that is just deprecated to get people to use UUID instead.
    Using it for this is perfectly fine.
     
  3. Offline

    Noctos

    Thanks ! I'll use the deprecated method but do you know why my request isn't working ?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Noctos You are probably just not following the redirects
     
Thread Status:
Not open for further replies.

Share This Page