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.
Amit JoshiPosted Mar 20, 2015, 9:36 AM
Pradeep ShetPosted Mar 19, 2015, 4:35 PM
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.