I have set up a basic MVC web API project with the following method in the ValuesController class -
// GET api/values/5
public string Get(int id)
{
return "Success!";
}
And calling this in the client like -
client.BaseAddress = new Uri("http://localhost:12345/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await client.GetAsync("api/values/5");
if (response.IsSuccessStatusCode)
{
result = await response.Content.ReadAsStringAsync();
}
I am relatively new t MVC however I am trying to modify this method to accept string variable to be used in a database call. For instance something like -
// GET api/values/number/house/street
public string Get(string no, string house, string street)
{
// use variables
return "Success!";
}
Then the client something like -
HttpResponseMessage response = await client.GetAsync("api/values/" + no + house + street);
if (response.IsSuccessStatusCode)
{
result = await response.Content.ReadAsStringAsync();
}
I am essentially trying to use the API as a webservice however unsure how to modify it to work in such a way.
When I tried the above code it returned Bad Request.