3

I'm currently trying to send two key values to server and get answer. My code ( 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();

Server code:

<?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";
}

for response Responsem.dart file:

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;
  }
}

I think my body is not correct because only value that I get from server side is "false:novalue" and statusCode is 200. I'm new, can you help please? Thanks...

hhilal
  • 163
  • 2
  • 4
  • 17

1 Answers1

0

The Flutter code is ok. The issue might be on the server. Check the server if it successfully receives the payload from the request.

Omatt
  • 8,564
  • 2
  • 42
  • 144