Android-通过javascript检测重定向
如果源URL被javascript重定向,我能得到最终URL吗 我正在使用okhttp获取响应,并检查响应代码。但对于某个URL,它会继续重定向到下一个URLAndroid-通过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
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