web api 服务器端写法
[HttpPost]
[ActionName("Simple")]
public string GetName([FromBody]string value)
{
string userName = value;
HttpContent content = Request.Content;
return "dddd";
}
[HttpPost]
[ActionName("StringSingle")]
public HttpResponseMessage GetUserEmail([FromBody]User value)
{
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("zhangjie")
};
if (value != null)
{
//User user = new UserHelper(this.context).GetUser(value.UserName);
//return user.Email;
response.Headers.Location = new Uri("http://www.baidu.com");
response.Content = new StringContent("http://www.baidu.com" value.UserName);
return response;
}
else
{
response.Headers.Location = new Uri("http://www.google.com");
response.Content = new StringContent("http://www.google.com");
return response;
}
}
[HttpPost]
[ActionName("Single")]
public User GetUser([FromBody]User value)
{
if (value != null)
{
User user = new UserHelper(this.context).GetUser(value.UserName);
return user;
}
else
{
return null;
}
}
评论