3

I'm using inappwebview package, which opens a web page. I want to receive some data from my Flutter app to my web page (php/html) or there's may be some better option? Basically the user select a product in the app and then the inappwebview package will open this web page to show some specific products).
I have found that inappwebview postData: "Loads the given [url] with [postData] using POST method into this WebView" and what I have tried is;

    controller.postUrl(
    url: "web link",
    postData: utf8.encode(data)
    );

And in web page (php) I don't know how this data receives, I tried to write it like this;

$data =utf8_decode($_POST['postData']);

Which is not correct i guess. Please help me!

1 Answer 1

0

The postData argument represents the Body of the HTTP POST request.

A simple example using the latest version 5.0.5+3 of the flutter_inappwebview plugin is:

var postData = Uint8List.fromList(utf8.encode("firstname=Foo&lastname=Bar"));
controller.postUrl(url: Uri.parse("https://example.com/my-post-endpoint"), postData: postData);

where the postData is the Body of the request in x-www-form-urlencoded format.

So, in your PHP server, you can access the firstname and lastname values as you normally would do, that is $_POST['firstname'] and $_POST['lastname'].

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.