[英]Download pdf with retrofit 2.3 with webView from moodle - Android
I am loading a url
in webView
, the webSite is php
base moodle
.In the webView is a lot *.pdf
and I need to download those pdfs
but I can't and just download login page . 我加载
url
在webView
,该网站是php
基础moodle
。在web视图是一个很大*.pdf
,我需要下载的pdfs
,但我不能,只需下载登录页面。 Notice : 注意 :
1- I login to webSite in webView
then I get the cookies
like bellow : 1-我在
webView
登录到webSite,然后得到像bellow这样的cookies
:
urlListClassWebView.setWebViewClient(new CustomBrowsers());
urlListClassWebView.getSettings().setLoadsImagesAutomatically(true);
urlListClassWebView.getSettings().setJavaScriptEnabled(true);
urlListClassWebView.clearHistory();
urlListClassWebView.setHorizontalScrollBarEnabled(false);
urlListClassWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
urlListClassWebView.loadUrl(url);
urlListClassWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (url.contains(".pdf")) {
String cookies = CookieManager.getInstance().getCookie(url);
}
}
});
2- Then I send cookies
to moodle
like bellow with retrofit 2.3 : 2 -然后我送
cookies
给moodle
喜欢与改造2.3波纹管:
@Headers({
"Referer: http://xx.xx.xx/course/view.php?id=2484",
"User-Agent: Mozilla/5.0 (Linux; Android 7.0; SM-G920F Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/62.0.3202.84 Mobile Safari/537.36",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Upgrade-Insecure-Requests: 1"
})
@POST
@FormUrlEncoded
Call<ResponseBody> downloadFile(@Url String url,
@Field("_ga") String _ga,
@Field("MoodleSession") String MoodleSession,
@Field("MOODLEID1_") String MOODLEID1_,
@Field("loglevel") String loglevel);
Resolved my problem : 解决了我的问题:
1-First I get cookies
the I create them like : aa=546345; bb=dfjds65;
1-首先我得到
cookies
,然后创建它们,例如: aa=546345; bb=dfjds65;
aa=546345; bb=dfjds65;
2-Then I pass it with retrofit like bellow : 2-然后我像波纹管一样通过改造:
@POST
Call<ResponseBody> downloadFile(@Url String url,
@Header("Cookie") String sessionIdAndToken);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.