0

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

IRON MAN
  • 191
  • 3
  • 18
  • Can you try this as return on try block: `WebResourceResponse("text/html", "utf-8", response.body()?.byteStream())`, Basically pass hard-coded strings for first two parameters and check whether issue is with that or not.. – Jeel Vankhede Nov 30 '21 at 12:03
  • @JeelVankhede now it is showing combination of ??? and text – IRON MAN Nov 30 '21 at 12:07
  • �����������������ot Entry�������� �F����WordD�4l�*0���Er� TS� � 2019 IJRAR February 2019, Volume 6, Issue 1 – IRON MAN Nov 30 '21 at 12:08
  • @JeelVankhede any idea ? – IRON MAN Nov 30 '21 at 12:12
  • I think it has something to do with mime-type and encoding.. one thing I'd suggest is to pass only string of individuals rather than wrapping them into `response.header()` – Jeel Vankhede Nov 30 '21 at 12:15
  • You can try this variation also: `WebResourceResponse(response.body()?.contentType()?.type(), null, response.body()?.byteStream())` – Jeel Vankhede Nov 30 '21 at 12:16
  • it showing blank @JeelVankhede – IRON MAN Nov 30 '21 at 12:18
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/239694/discussion-between-jeel-vankhede-and-iron-man). – Jeel Vankhede Nov 30 '21 at 12:19

0 Answers0