I can't do this in HttpURLConnection directly, since that would cause a forbidden dependency from Dalvik on Android.