I can't send post method body parameters in IOS emulator using InAppWebView with Flutter

46 views Asked by At

first of all, I'm very new to Flutter (actually, I'm not even new, when the mobile application developer friend at the company left, the mobile application project was left to me :) ) I am excited to share my first question on this platform with you.

In the flutter project prepared with VSCode, there is a method below regarding the webview method on one of the pages:

Future<void> postUrl() async {
    URLRequest? urlRequest;

    try {
      Map<String, String> headers = {
        'Content-Type': 'application/json; charset=UTF-8',
        'Authorization': 'Bearer ${loginData.token}'
      };

      String shortName = SharedMethods.languages
          .where((s) => s.number == loginData.languageNbr)
          .first
          .shortName;

      urlRequest = URLRequest(
        url: Uri.parse(pageUrl),
        method: 'POST',
        headers: headers,
        body: Uint8List.fromList(utf8.encode(
            "UserId=${loginData.userId}&Token=${loginData.token}&RefreshToken=${loginData.refleshToken}&CultureCode=$shortName&IsFlutter=true&DeviceId=${SharedMethods.DeviceId}")),
      );
      await _webViewController.loadUrl(urlRequest: urlRequest);
    } catch (e) {
      print(e);
    }
  }

In the above usage, everything is fine in the Android emulator, I can capture the body parameters (for example, at the requested address, in my project I prepared with .Net Core Razor Pages Web App:

var token = context.ModelState["Token"]?.RawValue;

var rtoken = context.ModelState["RefreshToken"]?.RawValue;

var userId = context.ModelState["UserId"]?.RawValue; . .

- I can receive the parameters I send from flutter as --),

but when I use the ios emulator, ModelState - Values comes empty ??

Info.plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>https</string>
    <string>http</string>
</array>
<key>io.flutter.embedded_views_preview</key>
<true/>
</dict>

on the relevant darts page:

return InAppWebView(
                        
                        initialOptions: InAppWebViewGroupOptions(
                          crossPlatform: InAppWebViewOptions(
                            mediaPlaybackRequiresUserGesture: false,
                            javaScriptEnabled: true,
                            javaScriptCanOpenWindowsAutomatically: true,
                            useShouldOverrideUrlLoading: true,
      
      preferredContentMode: UserPreferredContentMode.MOBILE, // ADD THIS
                          ),
                          android: AndroidInAppWebViewOptions(
      useHybridComposition: true,
      hardwareAcceleration: true,
    ),
    ios: IOSInAppWebViewOptions(
      allowsInlineMediaPlayback: true, 
    ),
                        ),
                        
                        onWebViewCreated: (controller) async {
                          _webViewController = controller;
                          await Permission.camera.request();
                          changePage(pageBtn);
                          await postUrl();
                        },
                        androidOnPermissionRequest:
                            (controller, origin, resources) async {
                          return PermissionRequestResponse(
                            action: PermissionRequestResponseAction.GRANT,
                            resources: resources,
                          );
                        },
                      );

I couldn't figure out why the body parameters are not showing when I use the iOS emulator. Can someone please help?

0

There are 0 answers