Home Ask Login Register

Developers Planet

Your answer is one click away!

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();





    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...)


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


Leave an answer

Quote of the day: live life