1
Answer

post data to API

darma teja

darma teja

7y
202
1
I am trying to post data to my API. Could anyone tell me where I missing??
I am getting error at:
 
  1. responseFinal = client.PutAsJsonAsync("apiName/api/blabla", data).Result;    
 
Here is my code:
  1. var client = new HttpClient();  
  2.   
  3. client.BaseAddress = new Uri("http://Ipaddress/apiName");  
  4. client.DefaultRequestHeaders.Accept.Clear();  
  5. client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));  
  6.   
  7. client.DefaultRequestHeaders.Authorization = CreateBasicHeader(userName, password);  
  8.   
  9. var data = new  
  10. {  
  11. data = "0001"  
  12. };  
  13.   
  14. HttpResponseMessage responseFinal = null;  
  15.    
  16. responseFinal = client.PutAsJsonAsync("apiName/api/blabla", data).Result;  // I am getting error  
Advance thanks,
Darma 
Answers (1)