How to get WebResourceRequest body in android webView

I need to change the request header of the android webView request. Therefore, I am adding the following code to the shouldInterceptRequest method. Here is my code.

@Override public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { try { String mUrl = request.getUrl().toString(); OkHttpClient httpClient = new OkHttpClient(); Request mRequest = new Request.Builder() .url(request.getUrl().toString()) .addHeader("token", UserHelper.getToken()) //add headers .build(); Response response = httpClient.newCall(mRequest).execute(); return new WebResourceResponse( getMimeType(request.getUrl().toString()), // set content-type response.header("content-encoding", "utf-8"), response.body().byteStream() ); } catch (Exception e) { return super.shouldInterceptRequest(view, request); } return super.shouldInterceptRequest(view, request); } 

Actually, it works, all requests carry a new header. However, as I create a new request, the original method / body of the request was lost. I do not know how to save the original method and body from WebResourceRequest.

+7
android webview
source share

No one has answered this question yet.

See related questions:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up Android emulator development?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to keep Android activity state by saving instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
6
Android: WebView should InterceptRequest not add RequestProperties to WebView
2
android webview measures the time of all resources

All Articles