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.

Pradeep ShetRank #595 · 4K reputationPosted Mar 19, 2015, 12:35 PM EDT
To pass the parameter you better pass in json format
like shown below-
var data = "{'':'100'}";
HttpResponseMessage response = client.PutAsJsonAsync(serviceURL,data).Result;
Hope this solves your problem . Plz mark it as answered if it helped you.
Amit Joshi111 reputationPosted Mar 20, 2015, 5:36 AM EDT