2

我正在使用 inappwebview 包,它会打开一个网页。我想从我的 Flutter 应用程序接收一些数据到我的网页(php/html),或者可能有更好的选择?基本上用户在应用程序中选择一个产品,然后 inappwebview 包将打开这个网页以显示一些特定的产品)。
我发现 inappwebview postData:“使用 POST 方法将给定的 [url] 和 [postData] 加载到此 WebView 中”,我尝试过的是;

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

而在网页(php)中我不知道这些数据是如何接收的,我试着这样写;

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

我猜这是不正确的。请帮我!

4

1 回答 1

0

postData 参数表示 HTTP POST 请求的正文。

使用最新版本5.0.5+3flutter_inappwebview插件的简单示例是:

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

其中是格式postData中的请求正文。x-www-form-urlencoded

因此,在您的 PHP 服务器中,您可以像往常一样访问firstname andlastname值,即$_POST['firstname']and $_POST['lastname']

于 2021-03-02T14:03:53.147 回答