How to inspect HTTP requests made by WebViews

2019-02-13 18:19发布

As you know, a lot of request (images, scripts, AJAX, etc.) are send when loading a single page. So I need to get all those request and inspect them.

So the question would be: How can I inspect the HTTP requests that are made when a WebView loads a page ?

I want: headers, method, status code, response, cookies.


Right now, I have:

 public  void onLoadResource(WebView view, String url){
    Log.d("my-tag", "onLoadResource = "  + url );
}

But that only shows me the URL.

3条回答
冷血范
2楼-- · 2019-02-13 18:23

The best you can get in your app is the WebViewClient.shouldInterceptRequest method, but that only has the URL. You currently can't get any of the things you've listed.

For debugging you can use Chrome DevTools if you're using Android 4.4.

查看更多
Root(大扎)
3楼-- · 2019-02-13 18:23

Look here: https://gist.github.com/kibotu/32313b957cd01258cf67 where you get the http headers at android >=21

查看更多
再贱就再见
4楼-- · 2019-02-13 18:36

The easiest way is to use a proxy. I use Charles, but I'm sure there are others. On the device, go to the WiFi settings, long click the one you're connected to, select "modify network" and enable the advanced options. There you'll be abel to configure the proxy settings for the whole device.

查看更多
登录 后发表回答