I am trying to call an api using .net maui but i am getting one or more errors occurred. (Connection failure) error and the api not hitting at all.
here is my code.
public async Task<string> SaveSmtpAsyc(SmtpDTO obj)
{
string res = "";
try
{
using (HttpClient httpClient = new HttpClient())
{
var uri = new Uri(Settings.BASEADDRESS);
httpClient.BaseAddress = new Uri( Settings.BASEADDRESS);
//httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.Timeout = TimeSpan.FromMinutes(5);
using (HttpRequestMessage request = new HttpRequestMessage())
{
var parms = new Dictionary<string, string>()
{
{"userId", obj.userId.ToString() },
{"port", obj.port.ToString() },
{"host", obj.host},
{"email", obj.email },
{"password", obj.password },
{"incoming", obj.incoming },
{"outgoing", obj.outGoing },
{"ssl", obj.ssl.ToString() }
};
var irequest = new StringContent(
JsonConvert.SerializeObject(parms),
Encoding.UTF8,
"application/json");
HttpResponseMessage response;
response = httpClient.PostAsync(
new Uri(uri, "api/smtp"),
irequest).GetAwaiter().GetResult();
if (response.IsSuccessStatusCode)
{
res = "true";
}
}
}
}
catch (AggregateException ex)
{
foreach (var errInner in ex.InnerExceptions)
{
string s = errInner.Message; //this will call ToString() on the inner execption and get you message, stacktrace and you could perhaps drill down further into the inner exception of it if necessary
}
res = ex.GetBaseException().Message;
}
return res;
}
can someone help me with this error, i used mysql db for apis. i am always getting the following error.
Getting one or more errors occurred. (Connection failure)
2