title: I get HTTP 400 when using oauth post request
body: <p>I am trying to use oauth for an application i am writing for android. I am getting so far that a proper authorization code is returned to my application. Now Í need to make a post request with that to get the access/refresh token. To do that I have to following code:  </p>
  
  <pre><code>class post_get_access_token extends AsyncTask&lt;String, Void, String&gt; {
  
  private Exception exception;
  
  protected String doInBackground(String... code) {
      try {
          String url = "https://login.eveonline.com/oauth/token";
          String charset = "UTF-8";
  
          String grant_type = "authorization_code";
          String enc_auth = Base64.encodeToString("9d7dcbb0380f450ea0d2b435b60f4c15:ssEAFgv5PfEs29bluxs9N3milKgC7j6saILCtMPw".getBytes(), Base64.DEFAULT);
  
  
          String query = null;
          try {
              query = String.format("grant_type=%s&amp;code=%s",
                      URLEncoder.encode(grant_type, charset),
                      URLEncoder.encode(code[0], charset));
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          }
          Log.i("eve_token_query",query);
  
          URLConnection connection = null;
          try {
              connection = new URL(url).openConnection();
          } catch (IOException e) {
              e.printStackTrace();
          }
          connection.setDoOutput(true); // Triggers POST.
          //connection.setRequestProperty("Accept-Charset", charset);
          connection.setRequestProperty( "Authorization", enc_auth);
          connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
  
          try (OutputStream output = connection.getOutputStream()) {
              output.write(query.getBytes());
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          for (Map.Entry&lt;String, List&lt;String&gt;&gt; header : connection.getHeaderFields().entrySet()) {
              Log.i("eve_response_header",header.getKey() + "=" + header.getValue());
          }
          //InputStream response = connection.getInputStream();
  
      } catch (Exception e) {
          this.exception = e;
  
          return null;
      }
  
      return "bla";
  }
  
  protected void onPostExecute(String... response) {
      // TODO: stuff
  }
  
  
  }
  </code></pre>
  
  <p>But the answer header is this:  </p>
  
  <pre><code>10-23 18:54:43.613 29926-30158/com.jbs.evecompanion I/eve_response_header: null=[HTTP/1.1 400 Bad Request]
  10-23 18:54:43.613 29926-30158/com.jbs.evecompanion I/eve_response_header: Connection=[close]
  10-23 18:54:43.613 29926-30158/com.jbs.evecompanion I/eve_response_header: Content-Length=[339]
  10-23 18:54:43.614 29926-30158/com.jbs.evecompanion I/eve_response_header: Content-Type=[text/html; charset=us-ascii]
  10-23 18:54:43.614 29926-30158/com.jbs.evecompanion I/eve_response_header: Date=[Sun, 23 Oct 2016 16:54:41 GMT]
  10-23 18:54:43.614 29926-30158/com.jbs.evecompanion I/eve_response_header: Server=[Microsoft-HTTPAPI/2.0]
  10-23 18:54:43.614 29926-30158/com.jbs.evecompanion I/eve_response_header: X-Android-Received-Millis=[1477241683613]
  10-23 18:54:43.614 29926-30158/com.jbs.evecompanion I/eve_response_header: X-Android-Response-Source=[NETWORK 400]
  10-23 18:54:43.614 29926-30158/com.jbs.evecompanion I/eve_response_header: X-Android-Selected-Protocol=[http/1.1]
  10-23 18:54:43.614 29926-30158/com.jbs.evecompanion I/eve_response_header: X-Android-Sent-Millis=[1477241683576]
  </code></pre>
  
  <p>Which as you can see gives me a "Bad Request".</p>