Hi All!
There is a webpage, what needs login and password. I have it both. I can view this webpage with webview well. There is a download possibility, but the webview can't download files so I try download by okhttpclient. Since the download link shows another php file, i.e.:
I read a lot and found (maybe) solution for this problem here: https://stackoverflow.com/questions/11224454/android-share-session-between-webview-And-httpclient, but I am not a clever man to translate this code into b4a:
, by the way I started, but there was error:
maybe since java version mismatch. The error was:
thanks in advance
Steven
There is a webpage, what needs login and password. I have it both. I can view this webpage with webview well. There is a download possibility, but the webview can't download files so I try download by okhttpclient. Since the download link shows another php file, i.e.:
and the download.php checks the login, will be an error, because I am logged in only on webview and not okhttpclient. Because the login datas are stored in PHP session variables, the httpjob.username/password are useless. I tried also set cookies:
B4X:
j.GetRequest.SetHeader("Cookie","[email protected];loginpass=yyyyy")
'or from the main webpage's cookies:
j.GetRequest.SetHeader("Cookie",CookieManager1.GetCookie("dital.hu"))
B4X:
public static String getCookieFromAppCookieManager(String url) throws MalformedURLException {
CookieManager cookieManager = CookieManager.getInstance();
if (cookieManager == null)
return null;
String rawCookieHeader = null;
URL parsedURL = new URL(url);
// Extract Set-Cookie header value from Android app CookieManager for this URL
rawCookieHeader = cookieManager.getCookie(parsedURL.getHost());
if (rawCookieHeader == null)
return null;
return rawCookieHeader;
}
B4X:
#If Java
import java.net.MalformedURLException;
import java.net.CookieManager;
import java.net.CookieHandler;
import java.net.CookiePolicy;
import java.net.URL;
public static String getCookieFromAppCookieManager(String url) throws MalformedURLException {
CookieManager cookieManager = CookieManager.getInstance();
if (cookieManager == null)
return null;
String rawCookieHeader = null;
URL parsedURL = new URL(url);
// Extract Set-Cookie header value from Android app CookieManager for this URL
rawCookieHeader = cookieManager.getCookie(parsedURL.getHost());
if (rawCookieHeader == null)
return null;
return rawCookieHeader;
}
#End If
May solve the main problem this approach?Javac 1.8.0_91
src\b4a\savehtml\main.java:918: error: cannot find symbol
CookieManager cookieManager = CookieManager.getInstance();
^
symbol: method getInstance()
location: class CookieManager
thanks in advance
Steven
Last edited: