using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost:60122");
User user = new User(){UserName = "UserName",Password = "Password"};
var response = client.PutAsJsonAsync("ChangePassword", user).Result;
if (response.IsSuccessStatusCode)
{
string responseString = response.Content.ReadAsStringAsync().Result;
}
}
Web Api code
[HttpPut]
[Route("ChangePassword")]
public void ChangePassword([FromBody]User ObjUser)
{
}
Member
141 Points
921 Posts
Help Needed in API URL access
May 12, 2015 06:49 PM|born2win|LINK
Hi,
I have created a Rest Services using web API2 and I am able to work with Get method. Having trouble to use POST and PUT. Question below,
How can i implement the multiple POST and PUT method in same controller?
on my UserController, i have below methods
when i try to execute, i am always getting null on the input parameters.
http://localhost:40744/api/user/ChangePassword
request body :
UserName = "Test" & password="Test123"
http://localhost:40744/api/user/ChangePin
request body:
UserName = "Test" & Pin="123"
Any suggestion how to implement this please and please help on achieving the multiple POST methods in the same class.
thakns
Contributor
2290 Points
493 Posts
Re: Help Needed in API URL access
May 12, 2015 08:32 PM|santhoshje|LINK
Try like this
Client code to call web api
Web Api code
Member
141 Points
921 Posts
Re: Help Needed in API URL access
May 12, 2015 09:18 PM|born2win|LINK
Hi Santhosh,
Thanks for you reply and Please advice me do i need to deserialize the what i receive in FromBody? Can you please use my sample code to achieve this.
thakns
Contributor
2290 Points
493 Posts
Re: Help Needed in API URL access
May 12, 2015 10:21 PM|santhoshje|LINK
You don't need to deserialize. Web Api will do it and bind parameters from body to user object. Please use like this
Member
141 Points
921 Posts
Re: Help Needed in API URL access
May 13, 2015 06:17 PM|born2win|LINK
Thanks, even without from body also working.