Retrofit2没有遵循重定向(HTTP 303,请参阅其他)

时间:2018-07-04 10:20:13

标签: http retrofit2 url-redirection

我正在开发一个收集Rss feed的Jee应用程序。

我有一个Source Rss端点列表,并使用Retrofit2来获取Rss内容

我有以下技术堆栈:-

WildFly Full 12.0.0.Final (WildFly Core 4.0.0.Final)

java.runtime.name = Java(TM) SE Runtime Environment
java.runtime.version = 1.8.0_121-b13
java.specification.name = Java Platform API Specification
java.specification.vendor = Oracle Corporation
java.specification.version = 1.8

retrofit-2.4.0

我的Retrofit组件类似于:-

public interface RssApi {
    @GET
    Flowable<Response<ResponseBody>> scrape(@Url final String url);

}

public class RssService implements RssApi {

    private static final String BASE_URL = "https://dummy.com/";

    private final RssApi service;

    public RssService() {
        final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        final OkHttpClient okHttpClient = new OkHttpClient.Builder().connectTimeout(60, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS).followRedirects(true).addInterceptor(interceptor).build();
        final Retrofit retrofit = new Retrofit.Builder().baseUrl(BASE_URL).client(okHttpClient).addConverterFactory(ScalarsConverterFactory.create()).addConverterFactory(JacksonConverterFactory.create()).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
        service = retrofit.create(RssApi.class);
    }

    @Override
    public Flowable<Response<ResponseBody>> scrape(final String url) {
        return service.scrape(url);
    }
}

除了我的来源Urls之外,所有功能都可以正常运行,如下所示

11:11:42,233 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) --> GET https://www.nature.com/subjects/biochemistry.rss
11:11:42,233 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) --> END GET
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) <-- 303 See Other https://www.nature.com/subjects/biochemistry.rss?error=cookies_not_supported&code=e52c3fe9-477f-4961-afdc-4337b93923a1 (264ms)
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) Content-Type: text/html
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) Server: Oscar Platform 201802052158-178
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) X-Vcap-Request-Id: ee0d0a81-46b7-49d4-70cf-8f86f3eacc2e
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) Accept-Ranges: bytes
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) Content-Length: 166
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) Accept-Ranges: bytes
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) Date: Wed, 04 Jul 2018 10:08:12 GMT
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) Via: 1.1 varnish
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) Connection: keep-alive
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) X-Served-By: cache-lcy19224-LCY
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) X-Cache: MISS
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) X-Cache-Hits: 0
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) X-Timer: S1530698893.580717,VS0,VE42
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) 
11:11:42,498 INFO  [okhttp3.OkHttpClient] (RxComputationThreadPool-7) <html>
<head><title>303 See Other</title></head>
<body bgcolor="white">
<center><h1>303 See Other</h1></center>
<hr><center>openresty</center>
</body>
</html>

我在followRedirects(true)上设置了okHttpClient,为什么仍然收到HTTP 303? error=cookies_not_supported有意义吗?

0 个答案:

没有答案