darma teja

darma teja

  • NA
  • 496
  • 329.2k

post data to API

Apr 20 2017 7:06 AM
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)