Amit Joshi

Amit Joshi

  • NA
  • 122
  • 35.4k

Calling WEB API from C# console application

Mar 19 2015 10:51 AM
I have web API service which has single Put method which takes one string parameter.
 
Put(string id)
 
I want to call the web API from C# console application.
 
I have below code.
 
client.BaseAddress = new Uri("http://localhost:8080");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
String Id="100";
string serviceURL="api/employee" 
 
HttpResponseMessage response = client.PutAsJsonAsync(serviceURL,Id).Result;
if (response.IsSuccessStatusCode)
{
 
 
The Id parameter is not getting mapped to the URL in order to call the Web API Put method.  How to send single parameter to Put method.
 
 
 
 

Answers (2)