I have a method based on which I bring response as SUCCESS
and FAILURE
. So on SUCCESS
status I want to make an API call which is https://testabc.com/xxxxx/pmp/xxx
Below is that method.
public void IsSiteIPLValidorNot(string NEID, out string response)
{
response = ""; string status = string.Empty;
response = CommonUser.GET_IPL_STATUS_ON_NEID(NEID);
if (response == "SUCCESS")
{
// call api here
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Site is not IPL');", true);
}
}
Do let me know how can be done in simple and easy way.
EDIT
The details of API is here.
url --location 'https://testabc.com/xxxx/pmp/xxx' \
--header 'Content-Type: application/json' \
--data '{
"A6_NEID": "INGJJMGRPVTGNB0001PMPAA6001",
"Azimuth": 10,
"Height": 26,
"VerticalBeamwidthTilt": 2,
"VerticalBeamwidth": 30,
"HorizantalBeam": 65,
"DistanceofCone": 500,
"SourceSystem": "MANUAL"
}'
Microsoft has a great documentation about making HTTP requests, but I'll also provide you an example for your case:
// Please, consider using IHttpClientFactory, instantiating a new handler for each request can lead to socket exhaustion
var httpClient = new HttpClient
{
// Think of this as the base url for all your api calls
BaseAddress = new Uri("https://testabc.com")
};
var content = new
{
A6_NEID = "INGJJMGRPVTGNB0001PMPAA6001",
Azimuth = 10,
Height = 26,
VerticalBeamwidthTilt = 2,
VerticalBeamwidth = 30,
HorizantalBeam = 65,
DistanceofCone = 500,
SourceSystem = "MANUAL"
};
// Send the request (automatically serializes the content as json and adds the content-type header)
HttpResponseMessage response = await httpClient.PostAsJsonAsync("/xxxx/pmp/xxx", content);
// This will throw an exception if the response is not successful
response.EnsureSuccessStatusCode();
// If you need to read the response, you can:
// Read as string
var result = await response.Content.ReadAsStringAsync();
// Or, deserialize to a class
var result = await response.Content.ReadFromJsonAsync<YourClass>();
// Etc...