Inconsistent HttpUrlConnection behaviours on Android - how to debug? - android

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

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.

Related

How to inspect network requests and responses happened in Android System WebView remotely?

Recently I have a problem in inspecting network requests and responses happened in Android System WebView.
The problem is that our app sometimes failed to load some urls with Android System WebView, but we can not get enough information to trace these cases.
Tools like Fiddler or Charles have some limitations like I should have access to that Android device, right?
And I also tried tools like Chrome Remote Debugging, this tool was amazing to debug problems in Android System WebView, but I should have Android device and development machine connected via USB, right?
So, is there any helpful things for me to inspect network requests and responses happened in Android System WebView remotely?
Thanks all.
Use Charles Proxy for inspecting network requests, it is pretty easy to use
this article will help
https://medium.com/#hackupstate/using-charles-proxy-to-debug-android-ssl-traffic-e61fc38760f7
add ssl proxy settings for the domain you want so that you can see the responses and requests clearly with headers and value you are sending in the body or in headers
if you want only remote debugging in chrome for webview
follow this
https://developers.google.com/web/tools/chrome-devtools/remote-debugging/?utm_source=dcc&utm_medium=redirect&utm_campaign=2016q3

Android emulator https proxy

I'm building an app (android + iOS) that needs to be able to reach an API Endpoint through a https proxy.
The development environment is Android Studio + Xcode + macOS.
My development path is:
Reach the endponit using android emulator settings.
Reach the endpoint using real andorid device settings.
Reach the endpoint using inapp solution implenting the https proxy connection management inside the app.
Since I'm at the first point, my problem is that I'm not able to setup the Android emulator with the https proxy.
(For iOS app, just setting up the mac network preferences is enought)
In Android, I successly set up the http, but not the https.
I have tried setting up the apn at the vitrual device, and running the emulator with -http-proxy.
According to the documentation it includes https proxy, but it still not working.
The debugger saids that the server response is null when calling https. Http redirects to https.
All of those solutions just works for the http, not for the https.
I have also tried whit genymotion with no success.
I have tested the API from my computer (via postman) and it is all ok.
Has anyone been able to successfully access an https proxy from the Android emulator? It's possible? What settings am I omitting?
Thank you so much in advance.
PS: My problem is related with HTTPS, I am able to use HTTP proxy

Bypassing Proxy in KSoap 2 in Android app in ICS 4.0.4

I have an Android application which connects to an HTTPS connection via the HttpTransportSE class of KSOAP2.
As of ICS 4.0.4, several 3G operators have been pushing incorrect definitions (ie. proxy server ip as the requested domain in the header sent to our server) which means connections are blocked by our server (for our accreditation, we cannot disable this).
e.g. the Apache error is: Hostname provided via SNI and hostname provided via HTTP are different
Is there any way of bypassing the phones proxy 3g settings (from the APN) in an android app to make a direct connection? I've looked everywhere and cannot find any answer to this.
Given this error in ICS 4.0.4 and the number of phones migrating to this version, it would be nice to get this error fixed :)
thanks! :)

unable to connect to https site on via both code and native browser

I have an android application that makes a https connection to a backend. I have successfully added the required certificate (obtained from the backend and converted to bks format) and the app can connect when running on 2.2, 2.3 and 4.0.2 emulators. However on my huawei u8860 (honor) with ics 4.0.3, the app doesn't connect and worst of all it doesn't give any exceptions in the log. On the phone also, I can't point the native browser to the backend but i can using google-chrome for android. I've searched high and low on but found no explanation for this behaviour. any ideas?! Thanks in advance
I suspect the problem is caused by your mobile carrier.
Some of them perform nasty filtering of HTTP requests, based on the User-Agent header (they'll block requests that do not seem to come from a mobile device).
You should try your app on your phone, using a Wifi connection to confirm/infirm this hypothesis.
If it works on Wifi, you should try to change the User-Agent of your HTTP requests, by either setting it to:
A hard-coded Android Chrome or iPhone Safari User-Agent (that you carrier probably does not block)
The User-Agent of your own device's browser that you should get with getUserAgentString()

Proxy and SSL connections in android emulator

Would anyone know how to configure the emulator to make ssl connections via a proxy ?
I use the -http-proxy option when starting the emulator. I can access any website except those with https protocol.
Any idea ?
I've experienced similar problems with Android during a web project lately. The site works fine using ordinary HTTP from Android but when using HTTPS it works now and then. Some requests just fail and we get "Web page not found"-errors. The connections are sometimes very slow. After some further tests and investigation I found out that the problem was general for all HTTPS sites, not only for our site.
According to a bug report for Android others are reporting the same problem and Android has been hit by it since version 1.5:
http://code.google.com/p/android/issues/detail?id=3334
I removed the APN proxy in my HTC Desire, as stated in the bug report above, and then Android performed as expected on HTTPS sites. For our purpose we have made an exception for Android telephone so they are routed to the ordinary HTTP site instead.
In other words, it seems like Android has a general problem with proxies and that may be the cause of problem with the emulator. Vote on the bug, just follow the link above.
There are several possible reasons for that:
Can you access the HTTPS site with your real phone? If not, then probably the involved certificate is not considered as trusted from the app/webview. If you need to consider a certificate as trusted within your app, look at the following tutorial
Can you access HTTPS sites at all via your proxy from a webbrowser? Our enterprise proxy server does not allow HTTPS traffic (for whatever reason) at all. You could also sniff the traffic with Wireshark etc. to see if anything is sent back from the proxy or an error occurred.
What type of problem did you get when you try to connect to the website? Can you provide a stacktrace or LogCat output?

Categories

Resources