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.DEFAULT]: Error on line 1, column 11: Invalid media type: expected /[^()<>@,;:"\\/[\]?={} \t\x00-\x1F\x7F #719

Closed
939582415 opened this issue Mar 25, 2020 · 9 comments

Comments

@939582415
Copy link

DioError [DioErrorType.DEFAULT]: Error on line 1, column 11: Invalid media type: expected /[^()<>@,;:"\/[]?={} \t\x00-\x1F\x7F

这个错误怎么解决下呢?返回的结果是如下样子,解析不出来啊
{
"code": 1,
"msg": "\u53d1\u9001\u6210\u529f"
}

@939582415
Copy link
Author

请求方法
Response response = await dio.post(
"im95b6f1efedcf6842/Login/get_verify_code",
data: formData);
print(response.data.toString());
BaseCode类
import 'package:json_annotation/json_annotation.dart';

part 'BaseCode.g.dart';

@JsonSerializable()
class BaseCode {
BaseCode(this.code, this.msg);

int code;
String msg;

@OverRide
String toString() {
return 'BaseCode{code: $code, msg: $msg}';
}
}

@939582415
Copy link
Author

I/flutter (31504): *** Request ***
I/flutter (31504): uri: =============================
I/flutter (31504): method: POST
I/flutter (31504): responseType: ResponseType.json
I/flutter (31504): followRedirects: true
I/flutter (31504): connectTimeout: 0
I/flutter (31504): receiveTimeout: 15000
I/flutter (31504): extra: {}
I/flutter (31504): headers:
I/flutter (31504): content-type: application/json; charset=utf-8
I/flutter (31504):
I/flutter (31504): *** DioError ***:
I/flutter (31504): uri: =============================
I/flutter (31504): DioError [DioErrorType.DEFAULT]: Error on line 1, column 11: Invalid media type: expected /[^()<>@,;:"\/[]?={} \t\x00-\x1F\x7F]+/.
I/flutter (31504): ╷
I/flutter (31504): 1 │ text/json;;charset=UTF-8
I/flutter (31504): │ ^
I/flutter (31504): ╵
I/flutter (31504):
E/flutter (31504): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: DioError [DioErrorType.DEFAULT]: Error on line 1, column 11: Invalid media type: expected /[^()<>@,;:"\/[]?={} \t\x00-\x1F\x7F]+/.
E/flutter (31504): ╷
E/flutter (31504): 1 │ text/json;;charset=UTF-8
E/flutter (31504): │ ^
E/flutter (31504): ╵
E/flutter (31504): #0 DioMixin._request._errorInterceptorWrapper. (package:dio/src/dio.dart:869:13)
E/flutter (31504):
E/flutter (31504): #1 _rootRunUnary (dart:async/zone.dart:1134:38)
E/flutter (31504): #2 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (31504): #3 _FutureListener.handleError (dart:async/future_impl.dart:157:20)
E/flutter (31504): #4 Future._propagateToListeners.handleError (dart:async/future_impl.dart:692:47)
E/flutter (31504): #5 Future._propagateToListeners (dart:async/future_impl.dart:713:24)
E/flutter (31504): #6 Future._completeError (dart:async/future_impl.dart:532:5)
E/flutter (31504): #7 _SyncCompleter._completeError (dart:async/future_impl.dart:57:12)
E/flutter (31504): #8 _Completer.completeError (dart:async/future_impl.dart:29:5)
E/flutter (31504): #9 Future.any. (dart:async/future.dart:462:45)
E/flutter (31504): #10 _rootRunBinary (dart:async/zone.dart:1146:38)
E/flutter (31504): #11 _CustomZone.runBinary (dart:async/zone.dart:1039:19)
E/flutter (31504): #12 _FutureListener.handleError (dart:async/future_impl.dart:153:20)
E/flutter (31504): #13 Future._propagateToListeners.handleError (dart:async/future_impl.dart:692:47)
E/flutter (31504): #14 Future._propagateToListeners (dart:async/future_impl.dart:713:24)
E/flutter (31504): #15 Future._completeError (dart:async/future_impl.dart:532:5)
E/flutter (31504): #16 _AsyncAwaitCompleter.completeError (dart:async-patch/async_patch.dart:38:15)
E/flutter (31504): #17 DioMixin._dispatchRequest (package:dio/src/dio.dart)
E/flutter (31504):
E/flutter (31504): #18 DioMixin._request._interceptorWrapper... (package:dio/src/dio.dart:849:37)
E/flutter (31504): #19 DioMixin.checkIfNeedEnqueue (package:dio/src/dio.dart:1117:22)
E/flutter (31504): #20 DioMixin._request._interceptorWrapper.. (package:dio/src/dio.dart:846:22)
E/flutter (31504): #21 new Future. (dart:async/future.dart:176:37)
E/flutter (31504): #22 _rootRun (dart:async/zone.dart:1122:38)
E/flutter (31504): #23 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (31504): #24 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (31504): #25 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:965:23)
E/flutter (31504): #26 _rootRun (dart:async/zone.dart:1126:13)
E/flutter (31504): #27 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (31504): #28 _CustomZone.bindCallback. (dart:async/zone.dart:949:23)
E/flutter (31504): #29 Timer._createTimer. (dart:async-patch/timer_patch.dart:23:15)
E/flutter (31504): #30 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19)
E/flutter (31504): #31 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
E/flutter (31504): #32 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
E/flutter (31504):

@stale
Copy link

stale bot commented Apr 24, 2020

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 Apr 24, 2020
@airingursb
Copy link

遇到同样的问题

@stale stale bot removed the stale label Apr 28, 2020
@fullstackuu
Copy link

After the upgrade of dio 3.0.9, all the old interfaces have problems, all of which are errors, How to solve this problem?

@stale
Copy link

stale bot commented Jun 17, 2020

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 Jun 17, 2020
@jaysephjw
Copy link

jaysephjw commented Jun 17, 2020

I am getting the same issue after upgrading from 2.2.2 to 3.0.9.

My Content-Type looks like application/json;.

Related dart-lang/http#180 ; dio can maybe use the workaround there.

@stale stale bot removed the stale label Jun 17, 2020
@stale
Copy link

stale bot commented Jul 17, 2020

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 Jul 17, 2020
@stale stale bot closed this as completed Jul 25, 2020
@JoweiBlog
Copy link

/// @see dart-lang/http#180

Response<Uint8List> response = await dio.post(
  'your_request_url',
  data: jsonEncode(data),
  options: Options(
    /// return bytes before run `isJsonMimeType` error.
    responseType: ResponseType.bytes,
  ),
);

/// try decode your data.
Map<String, dynamic> resData =
    json.decode(utf8.decode(response.data ?? []));


///  or try `dio.transformer` shoule be better.

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

5 participants