503 HTTP response code with OAUTH

android
oauth

#1

I try to get authorization token from Twitter (app-only), the code almost fully follows oficial guide, but get 503 Service unavailable code.

        @Override
    protected Boolean doInBackground(Void... params) {
        String cred_enc = tw_cons_key + ":" + tw_priv_cons_key;
        cred_enc = Base64.encodeToString(cred_enc.getBytes(), Base64.NO_WRAP);

        Request request = new Request.Builder().url("https://api.twitter.com/oauth2/token")
                .header("Authorization:", "Basic " + cred_enc)
                .header("Content-Type:", "application/x-www-form-urlencoded;charset=UTF-8")
                .post(RequestBody.create(MEDIA_TYPE_MARKDOWN, postBody))
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                ResponseBody body = response.body();
                if (response.isSuccessful()) {
                    Headers headers = response.headers();

                    //response check
                    for (int i = 0; i < headers.size(); i++) {
                        System.out.println("Headers: " + i + " " + headers.name(i) + " : " + headers.value(i));
                    }
                    System.out.println(body.string());

                    try {
                        JSONObject jsonObject = new JSONObject(body.string());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    throw new IOException("Unexpected code" + response);
                }
                body.close();
            }
        });
        return true;
    }

What may be the possible reason?


#2

The problem was with colons in header keys Content-Type: translated to Content-Type:: in actual request. After removing colons, everything worked as expected.