Solved Mojang URL encoding

Discussion in 'Spigot Plugin Development' started by FrostedSnowman, Jun 3, 2018.

  1. FrostedSnowman

    Resource Staff

    ok so I am making requests here:

    however, it returns a 400 error code (bad request), because
    of this:

    I'm not sure how to encode the URL.

    I copied the exact one from the wiki
    and encoded it like this:

    Code (Java):
    and i even outputted the value and got what was on the wiki, but still got the error code.

    The wiki says:
    The payload for this API consists of two url-encoded form fields (conjoined by '&').

    but I'm not sure what 'encoding' I'm suppose to specify here for the URL.
  2. The URL to Steve works fine in my browser. Show your full code please.
  3. FrostedSnowman

    Resource Staff

    Code (Java):
    String authenticityToken = this.getAuthToken(this.minecraftAccount);

    try {
        System.out.println("Token: " + authenticityToken);

        HttpURLConnection httpURLConnection = Webs.getConnection(String.format(UPLOAD_SKIN_URL, UUIDTypeAdapter.fromUUID(uuid)));


        httpURLConnection.setRequestProperty("Accept-Charset", "UTF-8");

        httpURLConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0");

        httpURLConnection.addRequestProperty("Authorization", "Bearer " + authenticityToken);
        try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(httpURLConnection.getOutputStream(), StandardCharsets.UTF_8))) {
            if (!normal) {

            writer.write("&url=" + UrlEscapers.urlFormParameterEscaper().escape(""));
            if (httpURLConnection.getResponseCode() >= 400) {
                System.out.println(IOUtils.toString(httpURLConnection.getErrorStream(), StandardCharsets.UTF_8));
        } catch (Exception exception) {
    } catch (Exception exception) {
    UUID type adapter is provided by the mojang auth package itself, just removes the dashes.
  4. FrostedSnowman

    Resource Staff


    solution: used postman to debug & inspected sent headers to mojang api
    • Friendly Friendly x 1