如何使Dio将HTTP 302代码作为常规HTTP代码而不是错误进行处理? (Http状态错误[302])

时间:2018-10-04 13:06:35

标签: http redirect dart flutter http-status-code-302

将登录数据发送到远程URL后,网站将返回302以及正确的登录Cookies。当使用http或HttpClient处理它时,状态代码302被处理为良好,但是使用Dio则被视为错误。

如何使Dio作为常规HTTP代码而不是错误来处理HTTP 302代码?

代码

Dio dio = new Dio();
dio.options.contentType = ContentType('application','x-www-form-urlencoded');
dio.post(urlLogin, data: data).then((Response resp){
  print('-----Login-----');
  List<String> headers = resp.headers['set-cookie'];
  headers.forEach((h) => print(h));
});

堆栈跟踪

Unhandled exception:
DioError [DioErrorType.RESPONSE]: Http status error [302]
#0      _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1112:29)
#1      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#2      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#3      _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:391:30)
#4      _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#5      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

0 个答案:

没有答案