com.android.volley.NoConnectionError - Android emulator with Charles Proxy
Asked Answered
P

2

16

I want to proxy network traffic for an Android emulator.

I can't seem to get it to work.

My emulator is booted up using this:

emulator @Nexus_5X_API_23 -http-proxy 10.0.1.17:8888

The IP and port points to what Charles reports in the Help menu.

The SSL certificate is installed. I can open the emulator browser and Charles shows me all traffic. The browser updates as usual.

All seems good so far.

Now I attempt to run my app. My first network call goes out successfully through Charles. The response returns and Charles displays it. However the response isn't passed to the app successfully.

I've set a breakpoint in the error callback and I can see a com.android.volley.NoConnectionError which is caused by java.io.IOException: unexpected end of stream on Connection.

Why doesn't Charles pass the result back back properly to the app?

Do I need to do what's defined at the end of the configuration page on Charles?

HttpHost httpproxy = new HttpHost("192.168.0.101", 8888, "http");
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,httpproxy);

This doesn't seem correct - what am I missing?

Profession answered 12/8, 2016 at 16:10 Comment(3)
You are talking about SSL certificate... Is your proxy SSL one? Or are you trying to connect to SSL protected website?Fustanella
If you want to monitor https traffic, I suggest u use Fiddler, which is more convenient in terms of this.Tater
what HttpStack do you use? try add -verbose-proxy when starting emulator and add to the question the output pleaseMunger
M
2

In order to help solving

java.io.IOException: unexpected end of stream on Connection

issue please answer the questions in the comments.

As regards to

HttpHost httpproxy = new HttpHost("192.168.0.101", 8888, "http"); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,httpproxy);

it will not help you just like that. In fact this is another way to apply a proxy which IMO is even better than '-http-proxy' because you can apply it anywhere not only for an emulator and it is only for this app build.

You need to apply the proxy in the Http Stack you use. for example:

public class ProxyHurlStack extends HurlStack {

    @Override
    protected HttpURLConnection createConnection(URL url) throws IOException {
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.1.17", 8888));
        HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
        return conn;
    }
}

and then for you debug build you can use smth like:

requestQueue = Volley.newRequestQueue(context, new ProxyHurlStack());
Munger answered 21/8, 2016 at 20:18 Comment(0)
C
-1

The only way to this is that install the SSL (Secure Socket Layer) certificate at server end then no need to set any Charles proxy.

Every enterprise has two development environments,

  1. Development ( http ) : doesn't need any SSL certificate
  2. Production ( https ) : needs SSL certificate

When production environment installs the SSL certificate then android emulator and Volley library automatically detects the network connection and your were able to consume the apis/web services as expected.

No other solution to this problem.

Capture answered 19/8, 2016 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.