如何拦截来自flutter_inappwebview的ajax post请求有效负载?

How to intercept ajax post request payload from flutter_inappwebview?

提问人:niang610 提问时间:10/6/2023 最后编辑:niang610 更新时间:10/6/2023 访问量:50

问:

我正在开发一个 Web 视图颤振程序,但遇到了一个问题。

我无法从 ajax post 请求中获取有效负载。

例如,我想在 Web 视图上单击登录按钮时获取登录信息。 我试过这样。

Flutter SDK 版本:flutter_windows_3.13.6-stable

webview_flutter:^4.4.1

path_provider:^2.1.1

InAppWebView(
        initialUrlRequest: URLRequest(url: Uri.parse('https://example.com')),
        onWebViewCreated: (controller) {
          _webViewController = controller;
          _webViewController.addJavaScriptHandler(
            handlerName: 'postPayload',
            callback: (args) {
              final payload = args.first;
              print('Received AJAX post payload: $payload');
            },
          );
        },
        onLoadStart: (controller, url) {
          print('Page started loading: $url');
        },
        onLoadStop: (controller, url) {
          print('Page finished loading: $url');
        },
        onLoadError: (controller, url, code, message) {
          print('Page resource error: $code - $message');
        },
        shouldOverrideUrlLoading: (controller, navigationAction) {
          final url = navigationAction.request.url;
          if (url.startsWith('https://www.youtube.com/')) {
            print('Blocking navigation to $url');
            return NavigationActionPolicy.CANCEL;
          }
          if (url.path.endsWith('.png') || url.path.endsWith('.jpg') || url.path.endsWith('.gif')) {
            return NavigationActionPolicy.CANCEL;
          }
          print('Allowing navigation to $url');
          return NavigationActionPolicy.ALLOW;
        },
        onLoadHttpError: (controller, url, statusCode, description) {
          print('HTTP error: $statusCode - $description');
        },
        onAjaxReadyStateChange: (controller, request) {
          if (request.method == 'POST') {
            final payload = request.requestData;
            print('Received AJAX post payload: $payload');
          }
        },
      ),
    );

但是onAjaxReadyStateChange处理程序,没有响应。 请帮帮我。 谢谢。

Ajax Flutter Post 有效负载 拦截

评论


答: 暂无答案