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]: FormatException: Unexpected character (at character 1) #27

Closed
fyzs-n9001 opened this issue Jul 13, 2018 · 10 comments

Comments

@fyzs-n9001
Copy link

fyzs-n9001 commented Jul 13, 2018

DioError [DioErrorType.DEFAULT]: FormatException: Unexpected character (at character 1)

@fyzs-n9001
Copy link
Author

请求是成功的, 服务端返回的是一个Base64编码的字符串

@fyzs-n9001 fyzs-n9001 changed the title 网络异常DioError [DioErrorType.DEFAULT]: FormatException: Unexpected character (at character 1) DioError [DioErrorType.DEFAULT]: FormatException: Unexpected character (at character 1) Jul 13, 2018
@wendux
Copy link
Contributor

wendux commented Jul 14, 2018

请贴出错误栈及触发的源码

@fyzs-n9001
Copy link
Author

随便弄个get接口,然后返回一个base64的字符串不就行了吗,你这个库里默认做了json格式校验吧

@wendux
Copy link
Contributor

wendux commented Jul 16, 2018

只有当返回头content-type指明为json时默认才会自动转换,如果你不想以让自动转换,可以指定接收的responseType, 文档里都有。

@akindone
Copy link

akindone commented Oct 23, 2018

when api is 500, response is <h1>Server Error (500)</h1> I use postman and find content-type is text/html . But I debug transformResponse find response's content-type is json ! (using default responseType) @wendux

@castrojr913
Copy link

castrojr913 commented Jun 14, 2019

@wendux I have a similar issue when field name has a camel case format. For instance:

FormData.from({ "verifyCode": jsonEncode({ "phone": phoneNumber, "zipcode": zipCode, "device_id": deviceId, "os_id": osId, } })

It throws FormatException: Unexpected character. However, if I replace verifyCode by verifycode, It works. It's really weird.

@gideonpeters
Copy link

gideonpeters commented Sep 23, 2020

I had this issue and turns out I was already decoding json in my base options and tried decoding it again in my logic to handle the response data. Like this:

already decoding it by specifying the responseType as ResponseType.json

BaseOptions options = new BaseOptions(
    contentType: ContentType.json.toString(),
    responseType: ResponseType.json,
    followRedirects: false,
    validateStatus: (status) {
      return status < 500;
    },
  );

and I was still trying to decode it here
return jsonDecode(response.data);

instead of just
return response.data;

@riskiadi
Copy link

better use http :p

@Godfather6666
Copy link

随便弄个弄个接口,然后返回一个base64的字符串不就行了,你这个库里默认了json格式的吧

我现在遇到这个问题了,可以请问你是怎么解决的吗

@nawzhin95
Copy link

any solution ?

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

8 participants