Monday, 1 May 2023

Android webview is returning invalid json string from google recaptcha

this is my webview settings

 domStorageEnabled = true;
 javaScriptEnabled = true;
       

this is my shouldInterceptRequest for web client

 val httpClient = OkHttpClient()
            val request: Request = Request.Builder()
                .url(url.trim { it <= ' ' })
                .addHeader("X-header", BuildConfig.RESET_USERNAME_PASSWORD_HEADER)
                .build()
            val response: Response = httpClient.newCall(request).execute()
            val headers: HashMap<String?, String?> = object : HashMap<String?, String?>() {
                init {
                    put("Access-Control-Allow-Origin", "*")
                    put("Access-Control-Allow-Methods", "*")
                    put("Access-Control-Allow-Headers", "*")
                    put("Content-Type", "*")
                }
            }
 WebResourceResponse(
                    null, "UTF-8",
                    200, "OK", headers, response.body?.byteStream()
                )

Log Error

 "Uncaught CustomError: Error in protected function: Invalid JSON 
 string: HTTP method GET is not supported by this "

So i received an html response instead of json

Is there a webview settings that i missed or request header that i should add besides from Access-Control-Allow-Methods

I also noticed that the recaptcha from webview is keep on loading and calling this url

https://www.google.com/recaptcha/api2/reload?k=6Ldsle8jAAAAALx90hxvqSDQPFW-DdJ4qmqk219K


from Android webview is returning invalid json string from google recaptcha

No comments:

Post a Comment