retrofit.dart icon indicating copy to clipboard operation
retrofit.dart copied to clipboard

please fix returning http code 302

Open arlakay opened this issue 1 year ago • 1 comments

Describe the bug i have issue with api that returning http code 302/303, and i need to read the response header. because redirect data in there.

if i using dio directly with same api, that return 302, & i can parse response header, but if i using retrofit it will returning 400 bad request, so i can't parse the response header.

i have set Options for both, it same result for retrofit can't return http status 302, forcing to 400 bad request.

      //   options: Options(
      //     followRedirects: false,
      //     maxRedirects: 0,
      //     validateStatus: (status) => status! < 500,
      //   ),

To Reproduce retrofit code

final result = await api.headerEnrichmentOffNet(
        url,
        options: Options(
          followRedirects: false,
          maxRedirects: 0,
          validateStatus: (status) => status! < 500,
        ),
      );

dio code

    var response = await dio.get(
        url,
        options: Options(
          followRedirects: false,
          maxRedirects: 0,
          validateStatus: (status) => status! < 500,
          contentType: "application/x-www-form-urlencoded",
        ),
      );

      if (response.statusCode == HttpStatus.found || response.statusCode == HttpStatus.seeOther) {
        final result = response.headers['Location']?.single;
        return left(MnvFailure.found(result));
      }

Expected behavior don't automatically redirect http response 302/303

Screenshots

Smartphone (please complete the following information):

  • Device: [Poco F5]
  • OS: [Android 13]

Additional context Add any other context about the problem here.

arlakay avatar Oct 26 '23 03:10 arlakay

Please share the generated code by retrofit.dart.

Let's see the difference between it and your code

trevorwang avatar Oct 27 '23 08:10 trevorwang