.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,594 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I tried to post to API but the C# code give me error "Failed to connect to localhost/127.0.0.1:7091"
while if I tried to use Postman , it will work,
for the recieved Json in APIService
{\"FullName\":\"Mark\",\"About\":null,\"Email\":\"aaa@kkk.com\",\"Image\":null,\"Phone\":null,\"Password\":\"1111\",\"Addresss\":null,\"Birthdat\":null,\"Role\":null,\"Id\":null}"
for the APIService
public class ApiServices
{
public static async Task<bool> RegisterUser(string FullName, string Email, string Password,string Phone)
{
try
{
var register = new User()
{
Email = Email,
Password = Password,
FullName = FullName,
Phone = Phone,
Image = "",
About = "",
Addresss = "",
Birthdat = "",
Role = "2",
CreatedDate = DateTime.Now.ToString("yyyy-MM-dd")
};
var httpClient = new HttpClient();
var json = JsonConvert.SerializeObject(register);
var content = new StringContent(json,Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync("
https://localhost:7091/api/Woners/AddWoners", content);
if (!response.IsSuccessStatusCode) return false;
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message); // give error Failed to connect to localhost/127.0.0.1:7091"
return false;
}
}
for the view model
private async void SignUpAsync()
{
var user = new User()
{
FullName=FullName, Phone=Phone, Email=Email,Password=Password
};
var responce=await ApiServices.RegisterUser(FullName, Email, Password,Phone);
}
{
Console.WriteLine("fals");
}