gpt4 book ai didi

android - DioError [DioErrorType.RESPONSE] : Http status error [400] Exception

转载 作者:行者123 更新时间:2023-12-03 03:38:30 49 4
gpt4 key购买 nike

我正在开发一个 Flutter Restful web 应用程序和 web api 后端作为 asp.net 核心。当我尝试使用发布请求发送表单数据时,它会抛出此错误

DioError [DioErrorType.RESPONSE]: Http status error [400] Exception



代码
onPressed: () async {
String email_value = emailController.text;
String password_value = passController.text;
String fullname_value = fullnameController.text;
var repassword_value = repassController.text;
print("$email_value");
if (password_value == repassword_value) {
try{
Dio dio = Dio();
var body = jsonEncode(
{
'FullName': '$fullname_value',
'Email': '$email_value',
'Password': '$password_value'
}
);
print("Body" + body);
Response response = await dio.post("http://iamtv.chainuniverse.com/api/Accounts/Register",
data: body,
options: Options(
contentType: Headers.jsonContentType,
)
);
var jsonData = json.decode(response.data);
print(jsonData);
if (response.statusCode > 200 &&
response.statusCode < 250) {
print("Sucess");
await loginAction();
print("Registered");
}
else{
print(jsonData);
}

但是当我在不使用 textcontroller Text 的情况下手动发送数据时,它可以工作。请帮我解决这个问题

在 POSTMAN 中完美工作
t

最佳答案

迟到的答案,可能对你有所帮助。

我遇到了同样的错误 Dioform-data .有效!添加后contentType

FormData formData = FormData.fromMap({
"image-param-name": await MultipartFile.fromFile(
imageFile.path,
filename: fileName,
contentType: new MediaType("image", "jpeg"), //add this
),
});

完整代码
var dio = Dio();
String fileName = imageFile.path.split('/').last;
FormData formData = FormData.fromMap({
"image-param-name": await MultipartFile.fromFile(
imageFile.path,
filename: fileName,
contentType: new MediaType("image", "jpeg"), //add this
),
});

var response = await dio.post(
"url",
data: formData,
options: Options(
headers: {
"Authorization": auth-token
},
),
onSendProgress: (int sent, int total) {
debugPrint("sent${sent.toString()}" + " total${total.toString()}");
},
).whenComplete(() {
debugPrint("complete:");
}).catchError((onError) {
debugPrint("error:${onError.toString()}");
});

关于android - DioError [DioErrorType.RESPONSE] : Http status error [400] Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59063095/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com