Flutter: Post request and set the params and string and the response is Integer

Viewed 36

I am new to flutter, I am trying to call this API that displays the params and the response.enter image description here

So I want to :

  • send the params as a string in a post request
  • the response will be received as int
  • make it in an HTTPS request.

I tried many ways to solve it but my status code is 405 and I didn't get the response as expected, here is my code below:

var response = await http
            .post(
              Uri.https('url',
                  'api/Employee/validate_user', {
                'domain_name': 'domainName' ,
                'user_name': _email,
                'password': encodedPassword,
                'token': '12345'
              }),
        
            )
            .then((value) => {
                  if (value.statusCode == 200)
                    {debugPrint(value.body)}
                  else
                    {
                      debugPrint(value.statusCode.toString() +
                          value.body.toString())
                    }
                });

kindly note that the email is retrieved from the textformfield field, and the password is encoded.

1 Answers

As per the postman screenshot, it has params that is query params. So, your request will be lie this.

var res = await post(Uri.parse('url/api/Employee/validate_user').replace(
  queryParameters: {
                'domain_name': 'domainName' ,
                'user_name': _email,
                'password': encodedPassword,
                'token': '12345'
  }
  ));
  
   if(res.statusCode ==200 ){
     
   }else {
      
   }

Just want to confirm is it POST request ?

Related