Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-通过javascript检测重定向_Javascript_Android_Redirect_Okhttp - Fatal编程技术网

Android-通过javascript检测重定向

Android-通过javascript检测重定向,javascript,android,redirect,okhttp,Javascript,Android,Redirect,Okhttp,如果源URL被javascript重定向,我能得到最终URL吗 我正在使用okhttp获取响应,并检查响应代码。但对于某个URL,它会继续重定向到下一个URL private okhttp3.Response responseOfRequestWithLink(String link) { try { CookieJar cookieJar = new PersistentCookieJar( new SetCookieCache(), n

如果源URL被javascript重定向,我能得到最终URL吗

我正在使用okhttp获取响应,并检查响应代码。但对于某个URL,它会继续重定向到下一个URL

private okhttp3.Response responseOfRequestWithLink(String link) {
try {
    CookieJar cookieJar = new PersistentCookieJar(
            new SetCookieCache(),
            new SharedPrefsCookiePersistor(context)
    );
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder()
            .followRedirects(true)
            .retryOnConnectionFailure(true)
            .readTimeout(15, TimeUnit.SECONDS)
            .writeTimeout(15, TimeUnit.SECONDS)
            .connectTimeout(15, TimeUnit.SECONDS)
            .cookieJar(cookieJar)
            .addInterceptor(interceptor)
            .build();

    Request request = new Request.Builder()
            .url(link)
            .build();


    return client.newCall(request).execute();
} catch (IOException e) {
    e.printStackTrace();
}
return null;
}
我不想在我的应用程序中使用WebView,只需要获取最终URL