2
Answers

Calling WEB API from C# console application

Amit Joshi

Amit Joshi

10y
6.9k
1
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)
Next Recommended Forum