I want to send SMS from my application. An SMS will send when I send a request for a specific URL. All my methods are asynchronous, but when I am an example HttpClientand want to use response.Content.ReadAsStringAsync(), I deleted await.
I do not want to wait for the response of this method and I want to send a request only to this URL. Now can you tell me this is a good solution?
This is my sample code:
public async Task<bool> SendMessage(string number, string body)
{
var from = _config["SMSSenderSettings:FromNumber"];
var username = _config["SMSSenderSettings:PanelUserName"];
var password = _config["SMSSenderSettings:PanelPassword"];
using (var client = new HttpClient())
{
try
{
var response = await client.GetAsync($"{BaseUrl}/send.php?method=sendsms&format=json&from={from}" +
$"&to={number}&text={body}&type=0&username={username}&password={password}");
response.EnsureSuccessStatusCode();
response.Content.ReadAsStringAsync();
return true;
}
catch (HttpRequestException)
{
return false;
}
}
}
I deleted awaitfrom response.Content.ReadAsStringAsync();and I received a warning.
source
share