How do you prevent Retrofit from automatically following a 302

前端 未结 5 1396
忘了有多久
忘了有多久 2021-02-18 23:43

I have an authentication call that i\'m trying to make using Retrofit on Android. The call returns a 302 to either a success or failure page. The original 302 response brings ba

5条回答
  •  时光说笑
    2021-02-19 00:35

    Event if the post is VERY old, here is my answer with OkHttp 3 just use the builder as the following

    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.followRedirects(false);
    OkHttpClient httpClient = builder.build();
    

    in a Response object (I use Retrofit actually), you'll find the redirect url in

    response.headers.get("Location")
    

    Hope this helps

提交回复
热议问题