Demortes February 2016

Android Connection not changing headers/request method

Given the following code:

    private HttpsURLConnection buildConnection(final String urlString) throws MalformedURLException,

        IOException, ProtocolException {

    final URL url = new URL(urlString);

    final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

    connection.setRequestMethod("POST");

    connection.setUseCaches(false);

    connection.setDoInput(true);

    connection.setDoOutput(true);
    connection.setChunkedStreamingMode(0);

    return connection;

}

Why does connection.method = "GET"? Any calls to addRequestProperty also seems to be ignored, as well.

This is using Android, Android Studio, on Windows to write the code (thus using whatever classes it downloads with the Android SDK, which should be the same as anyone else...)

Answers


Demortes February 2016

I found that my problem was the debugging windows for some reason were not updating. The code was changing the variables in memory, but the debugging windows in Android Studio AND Eclipse failed to reflect correct information.

My problem ultimately stemmed from an authorization header using a capital I instead of a lowercase I, causing unauthorized to be returned and the debugging information not reflecting correct information ultimately messed with what I thought was wrong, and led me down a rabbit hole for two days.

Post Status

Asked in February 2016
Viewed 1,156 times
Voted 6
Answered 1 times

Search




Leave an answer