Advertisement
yuvarajupadhyaya

Post HttpClient API call

May 19th, 2022
570
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private async Task CallAPI(List<Student> Studentlist)
  2.         {
  3.            
  4.  
  5.             var json = JsonConvert.SerializeObject(Studentlist);
  6.             var data = new StringContent(json, Encoding.UTF8, "application/json");
  7.  
  8.             var url = "https://learn2.guidedelearning.net/blank/studentUploadAPI/addMultipleNewUsers";
  9.              var client = new HttpClient();
  10.             client.DefaultRequestHeaders.Add("Token", "6819f6cb-1ceb-4860-998f-dd6407036e85");
  11.             client.DefaultRequestHeaders.Accept.Add(
  12.                     new MediaTypeWithQualityHeaderValue("application/json"));
  13.  
  14.             var response = await client.PostAsync(url, data);
  15.  
  16.             var result = await response.Content.ReadAsStringAsync();
  17.         }
Advertisement
RAW Paste Data Copied
Advertisement