We have a site with support for .net forms, which the user visits through the WebViewClient in our Android application. One of the features of the site is the ability to log in and download some PDF files, however you need to log in to download PDF files.
We are currently implementing shouldOverrideUrlLoading and loading pdf through the following code when the correct condition is met.
URL u = new URL(url); URLConnection conn = u.openConnection(); int contentLength = conn.getContentLength(); DataInputStream stream = new DataInputStream(u.openStream()); byte[] buffer = new byte[contentLength]; stream.readFully(buffer); stream.close(); DataOutputStream fos = new DataOutputStream(new FileOutputStream("/sdcard/download/file.pdf")); fos.write(buffer); fos.flush(); fos.close();
From the IIS logs, it is obvious that IIS does not consider this login request and redirects it to the login page.
We need a way to upload a file with an auth file saved in a file upload request, but we donβt understand how to save a cookie.
Another viable solution for us is to save the auth cookie between WebViewClient and the Android browser. If we can do this, we simply open the PDF file using the default action in the browser.
Edit: it looks like I can configure the auth cookie manually through
conn.setRequestProperty("Cookie", "");
Now I just need to figure out how to read auth cookie from WebViewClient
java android cookies asp.net-mvc forms-authentication
Allen rice
source share