Hello All respected SO members,
I am trying to build an android app with .NET MAUI.
I tried to save a content to MySQL database using HttpClient.PostAsync through PHP Api, however I can not make it work (the response is Success but the data is not saved to the table), while when I tried using POSTMAN to test with the PHP Api, everything is ok and it is able to save into the desired table.
.NET MAUI code
EmployeeData emp = new EmployeeData();
emp.emp_pin= EmpID.Text;
HttpClient cl = new HttpClient();
string js = JsonSerializer.Serialize(emp);
StringContent httpContent = new StringContent(js, Encoding.UTF8, "application/json");
var response = cl.PostAsync(Url, httpContent).Result;
if (response.IsSuccessStatusCode)
{
DisplayAlert("Success", "Success Record Your Data.", "OK");
}
else
{
DisplayAlert("Fail", "Please Try Again.", "OK");
}
Model
public class EmployeeData
{
public string emp_pin{ get; set; }
}
PHP API
<?php
require_once('dbhelper.php');
$json = file_get_contents('php://input');
$data = json_decode($json, true);
$emppin=$data['emp_pin'];
$sql = $conn->prepare("INSERT INTO test (emp_pin) VALUES (?)");
$sql->bind_param('s', $emppin);
$sql->execute();
if ($sql) {
echo json_encode(array('RESPONSE' => 'SUCCESS'));
} else {
echo json_encode(array('RESPONSE' => 'FAILED'));
}
Using POSTMAN, the data is successfully saved to the table.

Please highlight to me which part I made a mistake on.
