Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DioError [DioErrorType.RESPONSE]: Http status error [302] #265

Closed
ghozay19 opened this issue Apr 20, 2019 · 10 comments
Closed

DioError [DioErrorType.RESPONSE]: Http status error [302] #265

ghozay19 opened this issue Apr 20, 2019 · 10 comments

Comments

@ghozay19
Copy link

ghozay19 commented Apr 20, 2019

hi !

when im using dio post,
the post was successfull and the data was saved on the db.

but i check the logs, and got error code

DioError [DioErrorType.RESPONSE]: Http status error [302]

here's my code

_submit() async {    
var url =
        "https://script.google.com/macros/s/AKfycbyZMw-4aNli_vfIucxNxAZvIfWOtWlQEBST8EtDh4zGcDnEHCA7/exec?";

    try {
      var dio = new Dio();
      var response = await dio.post(
        url,
        queryParameters: {
          'action': 'insert',
          'tableName': 'presensi',
          'nis': nis,
          'nama': nama,
          'status': status
        },
        options: Options(
          connectTimeout: 5000,
          receiveTimeout: 10000,
        ),
      );

      print(response.toString());
    } on DioError catch (error) {
      if (error.response.statusCode == 302) {
        print("nani kore ? : " + error.toString());
      }
    }

note :
post was success but logs show 302.
how to resolve 302 code?

@zaubererty
Copy link

302 is the status code for a redirect.
I face the kind a same issue. My POST request to log in is awnserd with a 302 response. But i'm not sure wether the responded cockie is saved to the cockie jar.
The followup requests fail cause the cockie is not present.

@stale
Copy link

stale bot commented May 24, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label May 24, 2019
@stale stale bot closed this as completed May 31, 2019
@lyj0309
Copy link

lyj0309 commented Feb 17, 2020

i have a same question too

@2x2xplz
Copy link

2x2xplz commented Jul 26, 2020

I have the same concern as @zaubererty regarding cookies. Dio makes a POST request and receives a 302 response with a Set-Cookie header. However the redirected request does not appear to include the new cookie. I'm using the default CookieJar plugin with a PersistentCookieJar.

@alfawzaan
Copy link

alfawzaan commented Aug 5, 2020

Add followRedirects: false and validateStatus: (status) { return status < 500;} to the request

var response = await Dio().post("http://myurl",
data: requestBody,
options: Options(
followRedirects: false,
validateStatus: (status) { return status < 500; }
),
);

Source https://stackoverflow.com/questions/52537500/flutter-handle-status-code-302-in-post-request

@2x2xplz
Copy link

2x2xplz commented Aug 6, 2020

Thanks @alfawzaan
I'd suggest return status < 400; , as you probably want 404 not found , 401 unauthorized , etc to still raise errors. Also keep in mind if you aren't following redirects you'll need a manual way to send Dio to the relocated page, perhaps by reading the Location header

@josephantonyk94
Copy link

add header with
"Accept":"application/json" . henceforth it will only return json data otherwise it will prompt to redirect with html url, default dio configuration does not have response type so you have to mention it in header.

@jiashaoying
Copy link

use dio.request can solve this problem

@lucasromeiroTF
Copy link

use dio.request can solve this problem

Hello, how did you do this?
I always get 400 error if I use dio.request.
Could you give me an example?

@emondd4
Copy link

emondd4 commented Sep 25, 2024

Did Someone Finally Found the solution?

tried all the possible way that mentioned earlier but not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants