Android Question Send POST data with webview

Status
Not open for further replies.

JesusMujico

Member
Licensed User
Longtime User
Hi,
could someone please explain if it is possible to send POST data to a server running PHP by means of webview and how?


Thanks in advance!
 

JesusMujico

Member
Licensed User
Longtime User
You should use HttpUtils2 to send a POST request.
Hi Erel!
thanks for your kind and fast answer.
Yes I know and use HttpUtils2 to send POST requests but in this case the answer that I receive from the server is a web page dinamically created based on the POST value and need to show it in a webview.
I have seen that the webview for android has a postUrl method and I wonder if it possible to simulate it with the B4A version.
Perhaps it is possible to combine both (webview and httputils) but i don't know how.
Anyway if it is not possible thanks for your great software.
 
Upvote 0

JesusMujico

Member
Licensed User
Longtime User
WebView will create a post request when the user presses on a submit button of a POST form.
Yes I understand that webview works like a browser and can send a POST submit from a form but the problem I have here is there is not a form that interacts with the user. The server side code receives the POST requests directly by means of ajax and I have no access to modify that PHP.
Perhaps the easier solution would be to create an intermediate web page with a form (or javascript and ajax) and open it in the webview instead of connecting directly.

Well, anyway thanks for your support.
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
Despite this being an old question I was just trying to find out how to do the same sort of thing, that is craft an HTTP request and then POST it using Webview. ( Sometimes using HttpUtils2 is not going to be a solution to this problem if you already have an app using Webview).

This is a very simple way of creating a POST request and then sending it using Webview. Basically it creates a form on the fly and then using the submit-on-load option to post it.

B4X:
            dim Webview1 as Webview
            Dim html = $"<!DOCTYPE html>
            <html>"
            <body onload='document.frm1.submit()'>
            <form action='yoururl' method='post' name='frm1'>
              <input Type='hidden' name='param1' value='v1><br>
              <input Type='hidden' name='param2' value='v2><br>
              <input Type='hidden' name='param3' value='v3><br>
            
            </form>
            </body>
            </html>"$
            WebView1.LoadHtml(html)

Thanks to kmchmk on Stack Overflow for this idea in response to this question How to post data for WebView android
 
Upvote 0
Status
Not open for further replies.
Top