Android get request and response objects from webview - android

is there a way to get request and response objects from a webview?
for requests made from some webpage running in my webview, i want to intercept the full http request object(the headers, http method used, http body etc) and divert and send across that request into another channel.
For responses received from the webview, i want to do the same and get the object and its properties.
So far i have looked at the webviewClient android class which allows you to intercept url links executed by a webpage and intercept the resources it loads.
However, what i want to intercept, is any actual http requests the webpage makes. is this possible in Android webview?
thanks

That is not directly possible. You are welcome to write an HTTP proxy, then attempt to get WebView to work with that (e.g., see if it supports the http.proxyHost and http.proxyPort system properties).

Related

Android: How inspect http(s) request headers?

I'm developing an Android application, it is like a browser, has a web-view and sends http(s) requests. For debugging purpose, I want to be able to see the requests sent and received by the application (in particular the headers), but I'm unable to do so.
What i tried
I mainly debug the app with Chrome on PC, and use the Network Inspector in Chrome. The problem is that my app uses the ShouldInterceptRequest to intercept the requests an then manually sends a request with cronet. Chrome, in this case, shows some "provisional headers" that are from the original request, an not the headers of the actual request i sent manually.
I tried to use Fiddler and HTTP Toolkit, but the server I'm communicating with, doesn't like the certificate they use, so they can monitor correctly, but, if active, i cannot reach the page i need to monitor.
I also tried the Android Studio network inspector, but seems it work only for HttpURLConnection and Okhttp(1)
Thanks for your time.
If you're using a WebView, set a custom WebViewClient and override shouldInterceptRequest. That will pass in a WebResourceRequest object that will include all headers.

How to read body of a POST request into Android WebView

I have to submit a form to an external URL, that provides into my WebView a series of interaction with the user.
At the end of this process this external service does a redirect to my another URL (that is fake) through a POST call, sending some data that I need to show at the user.
I tried to catch this POST request into the method shouldInterceptRequest, because I have to read data before the load of my fake url starts, but the methods that I can use on a WebResourceRequest object are useless. There is nothing to read the body of this request.
There is another way to catch my data? Any suggestions?
(I already tried the writeinterception project library, but it doesn't work.)
Thanks a lot in advance.

Android intercept the response body and headers from a WebView?

I need to intercept the responses coming back from the response and redirects of a webview as it's loading?
I need to read the headers during the redirect, and I need to read cookies coming back.
Is this possible? Looking at some samples on stackoverflow, most solutions use shouldOverrideUrlLoading but that only gives you access to the url, and not the full response

Getting callback from payment gateway in webview

I am using Atom Payment Gateway for payments in my Android app. But this provider doesn't have an SDK for mobile platforms, also I cannot choose another provider because my client has been using Atom PG for their website for a long time.
So to make it work, I am now trying to call it in a webview in my app. All goes well until the last step except that I am not able to get the response from the PG upon completion of transaction.
As per their documentation:
After the completion of the transaction, the response will be posted back to the url provided by the merchant.
I already tried setting the return url to my reverse domain name and then setting an intent-filter but that doesn't seem to work.
Is there any method by which I can get the response that the PG "posts back" to the return url?
Here is an idea,
On getting the post request on your return url, you can parse that response and then via javascript send that to the JavascriptInterface linked to your WebView in the app
Intercepting POST data has been discussed:
How to intercept POST data in an android webview
Intercept POST requests in a WebView
Try this project : https://github.com/KeejOow/android-post-webview

Android Webview Response Reading

I am facing problem with reading response from the webview which loads a registration get url. The requirement is as below.
I have to communicate with a user registration servlet which can respond with html and xml content. For initial get request the servlet responds with html content and I can able to show that in WebView using load URL method. In the web view user enters the registration details and clicks submit, the servlet reponds with xml status code and registration details. I have to read this xml response from the servlet that can be obtained from the web view and do action (ex: close the web view and alert user) with respect to the xml response.
Please get me a solution.
I tried overriding Webview clients onPageFinsihed() and reading data again from the URL by opening an HTTP connection. I think this implementation communicates with the server two times, Is that correct?
Regards
#nish
You need to actually extract HTML from the WebView, this can be done in different ways this is one approach.

Categories

Resources