4

I'm trying to integrate the AADHAR API in my flutter application.

To work with the api I have used InAppWebView plugin in the application.

For more details I have shared below my code:

class AaadharWebView extends StatelessWidget {
  AaadharWebView(
      {Key? key, required this.targetUrl, required this.requestPayload})
      : super(key: key);
  final String targetUrl;
  final String requestPayload;

  final AppStateController _appState = Get.find<AppStateController>();
  InAppWebViewController? webViewController;

  @override
  Widget build(BuildContext context) {
    Uint8List payload = Uint8List.fromList(utf8.encode("msg:$requestPayload"));
    return Scaffold(
      appBar: AppBar(title: const Text("Aadhar Linking")),
      body: InAppWebView(
        initialUrlRequest: URLRequest(
            url: Uri.parse(targetUrl),
            method: 'POST',
            body: payload,
            headers: {
              'Content-Type': 'multipart/form-data',
              'Content-Length': payload.length.toString(),
            },
            ),
        onWebViewCreated: (controller) async {
          webViewController = controller;
          webViewController?.clearCache();
        },
      ),
    );
  }
}

Here, requestPayload => contains the valid XML format targetUrl => contains the valid URL

Please do not bother about the correct data in above 2 fields. Those contains the valid data.

I have tested this with the help of POSTMAN. And I got the expected result. Under the hood Postman uses http.MultipartRequest. But in our case InAppWebView takes the UInt8List type of data only.

Response: Please see the below image

NSDL WebPage ScreenShot

Can anyone please help me, How can I send form data or multipart request in InAppWebView flutter?

Sahil
  • 41
  • 2

0 Answers0