Inconsistent HttpUrlConnection behaviours on Andro

2019-06-28 02:47发布

问题:

I have a weird problem: Implementing an interface to a webserver in my Android App, I connect to it using a HttpsUrlConnection. The connection uses additional HTTP Basic authorization (using setRequestProperty), but otherwise is a plain GET request over HTTPS.

It works perfectly fine using it on the emulator using Android 4.0.3, but fails with a "Bad request" HTTP 400 Error on Android 2.3.5 (both emulator and real device). I do not have control over the server, so I cannot see what the problem exactly is.

Has anyone ever encountered such a problem or knows how to print/log the request that actually is being sent?

TIA,

Patrick

回答1:

You could set up a proxy such as Fiddler or Charles proxy (and I think there are firefox extensions as well) and point your app to the proxy instead. Even if you don't set it up to actually be a proxy (such that the requests actually work), as long as it captures the requests you should be able to compare the difference between the requests made from 4.0.3 vs. 2.3.5.