i refering this answer --> Send authorization header with every request in webview using okhttp in android
but im getting something like this
[![enter image description here][1]][1]
i also tried text/html and html/plain but it didnt help
following is my code:-
val wvc: WebViewClient = object : WebViewClient() {
override fun shouldInterceptRequest(view: WebView, url: String): WebResourceResponse? {
return try {
// val acToken: String = pref.getString("token", "DEFAULT")
val okHttpClient = OkHttpClient()
val request: Request = Request.Builder().url(url).addHeader("Authorization", "Bearer $bearer").build()
val response: Response = okHttpClient.newCall(request).execute()
WebResourceResponse(response.header("content-type", response.body()?.contentType()?.type()), // You can set something other as default content-type
response.header("content-encoding", "UTF-8"), // Again, you can set another encoding as default
response.body()?.byteStream()
)
} catch (e: IOException) {
e.printStackTrace()
null
}
}
}
setting to webview
webview_comp.setWebViewClient(wvc);
url?.let { webview_comp.loadUrl(it) };
any help will thankful here is the output [1]: https://i.stack.imgur.com/5trdD.png