My Flutter app allows user to access a webpage which requires authentication via Flutter InAppWebView. The webpage allows authenticated user to download a PDF file so I handle the download using the FlutterDownloader in the onDownloadStart event of InAppWebView.
When I try to download the file after logging onto the webpage, the app downloads the Index page of the website instead of the PDF file. Checking the debug logs reveals that the URL was redirected to the login URL:
D/DownloadWorker(15942): Open connection to [PDF URL]
D/DownloadWorker(15942): Response with redirection code
D/DownloadWorker(15942): Location = [Index path]
D/DownloadWorker(15942): New url: [Index page URL]
D/DownloadWorker(15942): Open connection to [Index page URL]
D/DownloadWorker(15942): Headers = {"authorization": "Basic [Auth-token]","connection": "keep-alive"}
D/DownloadWorker(15942): Content-Type = text/html; charset=utf-8
D/DownloadWorker(15942): Content-Length = -1
D/DownloadWorker(15942): Charset = UTF-8
D/DownloadWorker(15942): Content-Disposition = null
D/DownloadWorker(15942): fileName = Index
D/DownloadWorker(15942): Update notification: {notificationId: 22, title: Index, status: 2, progress: -409600}
D/DownloadWorker(15942): There's no application that can open the file /storage/emulated/0/Download/Index (16)
D/DownloadWorker(15942): Update too frequently!!!!, but it is the final update, we should sleep a second to ensure the update call can be processed
D/DownloadWorker(15942): Update notification: {notificationId: 22, title: Index, status: 3, progress: 100}
D/DownloadWorker(15942): File downloaded
I/WM-WorkerWrapper(15942): Worker result SUCCESS for Work [ id=8e03335b-c319-445e-8622-d22bacf34568, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]
I tried saving the cookies and downloading the file using http package but it still get's redirected. I need to allow user to download the PDF file from the current webview.
Any suggestion to resolve the issue would be appreciated.
Thank you.