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

Access the HTTP address error FormatException: Bad utf-8 encoding 0x89 #44

Closed
pyp163 opened this issue Jul 30, 2018 · 3 comments
Closed

Comments

@pyp163
Copy link

pyp163 commented Jul 30, 2018

dio: ^0.1.7

Access the HTTP address error FormatException: Bad utf-8 encoding 0x89, the correct return content of HTTP is binary

try {
       Response responses = await DioUtils.DioHttp().post(url, data: formData);
       print('返回:${responses.data.toString()}');
     }on DioError catch(e){
       print('错误:'+e.message);
     }

错误:FormatException: Bad UTF-8 encoding 0x89 (at offset 0)

@wendux
Copy link
Contributor

wendux commented Jul 30, 2018

你formdata中的内容和url分别是什么?

:octocat: From gitme Android

@pyp163
Copy link
Author

pyp163 commented Jul 31, 2018

@wendux
FormData formData = new FormData.from({
"token": token,
"nonce": nonce8,
"timestamp": time.toString(),
"sign": sign,
});
{token: v6b3aSqLJp6YpWmnWvuCip7W, nonce: BMnMKZXE, timestamp: 1533005903, sign: ea9efa98cf29e992db8b1ce9138ee6a26313e43ee67f9ef6bd900408efc95864}

url = Constants.api + "/GetVerify"
接口返回的是二进制图片,其实的接口都正常就这个不行,这个接口在java代码上是正常的

@wendux
Copy link
Contributor

wendux commented Jul 31, 2018

二进制数据要指定responseType为stream , 这样response.data便会是steam, dio默认是以字符串方式来解码的

:octocat: From gitme Android

@wendux wendux closed this as completed Jul 31, 2018
AlexV525 added a commit that referenced this issue Feb 13, 2023
Signed-off-by: Alex Li <github@alexv525.com>

Signed-off-by: Alex Li <github@alexv525.com>
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

2 participants