[英]How can pass the request parameter as a formdata in dart or flutter
I have tried many formats to pass the request parameter in the flutter project but I'm getting API status code 415 and Unhandled Exception: FormatException: Unexpected end of input (at character 1)
.我尝试了多种格式来传递 flutter 项目中的请求参数,但我得到 API 状态代码 415 和
Unhandled Exception: FormatException: Unexpected end of input (at character 1)
。 I have added the postman image for the understanding of the form data.我添加了 postman 图像,用于了解表单数据。
For Flutter HTTP library it goes like this,对于 Flutter HTTP 库,它是这样的,
var headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
var request = http.Request('POST', Uri.parse(''));
request.bodyFields = {
'firstName': 'Keval',
'lastName': 'ebiz',
'email': 'al@gmail.com',
'phone': '1234'
};
request.headers.addAll(headers);
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.