TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tamil Iniyan
NA
79
7.6k
how to post web api frombody parameter together with simple
Mar 10 2017 1:37 AM
I am trying to pass the id and employeemodel object in below format but it throws an error like method not allowed
string.Format("id=1007&EmployeeID={0}&EmployeeName={1}&EmployeeDept={2}&EmployeeEmail={3}&EmployeePhone={4}", 1007, "guna", "HR", "
[email protected]
", "9566764152")
WEB API METHOD:
public void Put(int id, [FromBody]EmployeeModel value)
{
employeeRepository.UpdateEmployee(id, value);
}
class:
public class EmployeeModel
{
[Key]
public int EmployeeID { get; set; }
[Required(ErrorMessage = "Enter Name")]
public string EmployeeName { get; set; }
public string EmployeeDept { get; set; }
public string EmployeeEmail { get; set; }
public string EmployeePhone { get; set; }
}
Client request:
WebResponse response;
HttpWebRequest request;
string postString = string.Format("id=1007&EmployeeID={0}&EmployeeName={1}&EmployeeDept={2}&EmployeeEmail={3}&EmployeePhone={4}", 1007, "guna", "HR", "
[email protected]
", "9566764152");
request = (HttpWebRequest)WebRequest.Create("http://localhost:6267/api/employeevalue");
request.Accept = "application/json";
request.Method = "PUT";
request.ContentType = "application/x-www-form-urlencoded";
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream());
requestWriter.Write(postString);
requestWriter.Close();
response = (HttpWebResponse)request.GetResponse(); // geting method not allowed error.
Reply
Answers (
4
)
Problem with posting data to Web API
How to get the descendants from xml SOAP response