我正在开发Flutter Restful Web应用程序和Web API后端作为asp.net核心。当我尝试使用邮寄请求发送表单数据时,会引发此错误
DioError [DioErrorType.RESPONSE]:Http状态错误[400]异常
代码
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手动发送数据时,它就可以工作。请帮我解决这个问题
答案 0 :(得分:1)
最新答案可能会对您有所帮助。
我在200
和/api/test/123/
上遇到了同样的错误。有效!添加{ package spark
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.{col}
object filterWorld extends App {
val spark = SparkSession.builder()
.master("local")
.appName("Mapper")
.getOrCreate()
import spark.implicits._
case class Person(
ID: Int,
firstName: String,
lastName: String,
description: String,
comment: String
)
val personDF = Seq(
Person(1, "FN1", "LN1", "TEST", "scala"),
Person(2, "FN2", "LN2", "develop", "spark"),
Person(3, "FN3", "LN3", "test", "sql"),
Person(4, "FN4", "LN4", "develop", "java"),
Person(5, "FN5", "LN5", "test", "c#"),
Person(6, "FN6", "LN6", "architect", "python"),
Person(7, "FN7", "LN7", "test", "spark"),
Person(8, "FN8", "LN8", "architect", "scala"),
Person(9, "FN9", "LN9", "qa", "hql"),
Person(10, "FN10", "LN10", "manager", "haskell")
).toDF()
personDF.show(false)
// +---+---------+--------+-----------+-------+
// |ID |firstName|lastName|description|comment|
// +---+---------+--------+-----------+-------+
// |1 |FN1 |LN1 |TEST |scala |
// |2 |FN2 |LN2 |develop |spark |
// |3 |FN3 |LN3 |test |sql |
// |4 |FN4 |LN4 |develop |java |
// |5 |FN5 |LN5 |test |c# |
// |6 |FN6 |LN6 |architect |python |
// |7 |FN7 |LN7 |test |spark |
// |8 |FN8 |LN8 |architect |scala |
// |9 |FN9 |LN9 |qa |hql |
// |10 |FN10 |LN10 |manager |haskell|
// +---+---------+--------+-----------+-------+
//
val fltr = !col("description").like("%e%") && !col("comment").like("%s%")
val res = personDF.filter(fltr)
res.show(false)
// +---+---------+--------+-----------+-------+
// |ID |firstName|lastName|description|comment|
// +---+---------+--------+-----------+-------+
// |9 |FN9 |LN9 |qa |hql |
// +---+---------+--------+-----------+-------+
}
Dio
完整代码
form-data