amerzafar
12/18/2017 - 4:24 AM

send api call async.cs

send api call async.cs

private static string sendApiCall(string msisdnlist)
{
    string url = "https://msisdn.production.dtconnect.net/api/Msisdn/";
    //string url = "https://msisdn.qa.dtconnect.net/api/Msisdn/";
    //string url = "http://localhost:8026/api/Msisdn/";

    var client = new HttpClient();

    string result = "";

    string json = "{\"msisdn\": \""+ msisdnlist + "\",\"status\": 4}";

    var stringContent = new StringContent(json, Encoding.UTF8, "application/json");

    var task = client.PostAsync(url, stringContent)
          .ContinueWith((taskwithresponse) =>
          {
              var response = taskwithresponse.Result;
              var jsonString = response.Content.ReadAsStringAsync();
              jsonString.Wait();
              result = jsonString.Result;
          });
    task.Wait();

    return result;
}