title: Why do I keep getting Error 400 after post in Android?
body: <p>I'm building an app that logs with user credentials to Spotify. I follow this API call: <a href="https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow" rel="nofollow noreferrer">https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow</a></p>
  
  <p>And this is the implenentation code:</p>
  
  <pre><code>@Override
  protected Session doInBackground(String... params) {
  
      Session session = new Session();
  
  
  
      try {
          String response = "";
          URL url = new URL(GET_TOKEN_URL);
          HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  
          String credentials = params[0]+":"+params[1];
          String basicAuth ="Basic "+new String(android.util.Base64.encode(credentials.getBytes(), Base64.DEFAULT));
  
          Uri.Builder builder = new Uri.Builder()
                  .appendQueryParameter(GRANT_TYPE, CLIENT_CREDENTIALS);
          String query = builder.build().getEncodedQuery();
          httpURLConnection.setRequestProperty(AUTH, basicAuth);
          httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          httpURLConnection.setRequestProperty("Content-Language", "en-US");
          httpURLConnection.setDoInput(true);
          httpURLConnection.setUseCaches(false);
          httpURLConnection.setDoOutput(true);
          httpURLConnection.setRequestMethod(POST);
  
  
          httpURLConnection.connect();
  
          OutputStream os = httpURLConnection.getOutputStream();
          BufferedWriter writer = new BufferedWriter(
                  new OutputStreamWriter(os, "UTF-8"));
  
          writer.write(query);
          writer.flush();
          writer.close();
          os.close();
  
          int responseCode=httpURLConnection.getResponseCode();
  
          session.setResponseCode(responseCode);
  
          if (responseCode == HttpsURLConnection.HTTP_OK) {
              String line;
              BufferedReader br=new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
              while ((line=br.readLine()) != null) {
                  response+=line;
              }
          }else{
              Log.e(getClass().getSimpleName(), "RESPONSE:" + responseCode);
             // response = "Something went wrong";
          }
          Log.d(getClass().getSimpleName(), response);
  
      } catch (MalformedURLException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      } finally{
  
      }
      return session;
  }
  </code></pre>
  
  <p>But no matter what I change, I'm always getting an Error 400.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Update:</p>
  
  <p>I performed a curl with an online tool following the exact syntax of the Spotify Developer webpage and I still have an HTTP STATUS 400 <a href="https://i.stack.imgur.com/WcK6R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WcK6R.png" alt="enter image description here"></a></p>