flutter-Auto submitting an xml form in flutter.Auto Submit Form, get XML returned on next page, then Auto Submit the new form with XML data?

Viewed 168

I am sending a post request to an api from which i am getting an xml form and url to whom i have to auto submit the xml form .I have tried two approaches : 1.using Inappwebview

     ```
  InAppWebView(
    initialUrlRequest: URLRequest(
        url: Uri.parse(targetUrl),
        method: 'POST',
        body: Uint8List.fromList(utf8.encode("msg=${requestPayload}")),
        headers: {
          'Content-Type': 'multipart/form-data',
                      }),

    ```
2. using webview and html
load() {
    final html = '''<!DOCTYPE html><html><body>
<script>
   setTimeout(myGreeting, 600000);
   function myGreeting() {
   document.getElementById('aadhaarForm').submit();
  } 
</script>
  <form action="$targetUrl"
    id="aadhaarForm"
    name="aadhaarForm"
    method="post"
    enctype="multipart/form-data">
    <input type="hidden"
        id="xmlid"
        name="msg"
        value="$requestPayload" />
</form>
</body></html>''';
    print(html);
    return html;
  }

  void loadHtml() async {
    final url = Uri.dataFromString(
      await load(),
      mimeType: 'text/html',
      encoding: Encoding.getByName('utf8'),
    ).toString();

    controller.loadUrl(url);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text("webview")),
        body: WebView(
          javascriptMode: JavascriptMode.unrestricted,
          onWebViewCreated: (controller) async{
            this.controller = controller;
            await Future.delayed(const Duration(seconds: 1));
            loadHtml();
          },
        

But i am getting the error authentication failed as request is being modified after submission , So how can i autosubmit my xml form without modifying it ?

0 Answers
Related