3

我目前正在尝试将两个键值发送到服务器并获得答案。我的代码(main.dart):

Future<Responsem> createResponsem() async {

 Map<String, dynamic> jsonMap = {
      "email":"user",
      "pass":"1234"
    };
  final http.Response response = await http.post(url,
      body: json.encode(jsonMap),
      headers: {
        "Accept": "application/json",
        "Content-Type": "application/x-www-form-urlencoded"
      },
      encoding: Encoding.getByName("utf-8"));

  print(response.statusCode);
     return Responsem.fromJson(json.decode(response.body));
}
createResponsem();

服务器代码:

<?php
$email = filter_input(INPUT_POST,"email");
$pass = filter_input(INPUT_POST,"pass");

if(isset($email) && isset($pass)){
  if($email == "user" && $pass = "1234"){
    echo "true";
    }else{
        echo "false:wrongvalues";
    }
}else{
    echo "false:novalue";
}

对于响应 Responsem.dart 文件:

class Responsem {
 String completed;

  Responsem({this.completed});

  Responsem.fromJson(Map<String, dynamic> json) {
    completed = json['completed'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['completed'] = this.completed;
    return data;
  }
}

我认为我的身体不正确,因为我从服务器端获得的唯一值是“false:novalue”,statusCode 是 200。我是新手,你能帮忙吗?谢谢...

4

1 回答 1

0

Flutter 代码没问题。问题可能出在服务器上。检查服务器是否成功接收到来自请求的有效负载。

于 2021-06-11T09:36:08.483 回答