使用moodle的AndroidView下载带有改进2.3的pdf - Android

时间:2017-12-06 11:52:32

标签: php android cookies retrofit2 moodle

我正在url加载webView,网站php基地为moodle。在webView中有很多*.pdf我需要下载那些pdfs但我无法下载登录页面。 注意:

1-我在webView登录webSite然后我得到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-然后我将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);

1 个答案:

答案 0 :(得分:0)

解决了我的问题:

1 - 首先我得到cookies我创建它们:aa=546345; bb=dfjds65;

2 - 然后我按照下面的改进传递它:

@POST
Call<ResponseBody> downloadFile(@Url String url,
                                @Header("Cookie") String sessionIdAndToken);