C# WebApi 请求方式Post,返回Response
1.[FromBody]属性只能用在一个参数上,当Body中有多个参数要定义类型。一个参数的时候 key="",value="123",key为空才能取到值。
2.返回String类型时内容前后会有双引号。要用HttpResponseMessage类型。
1 [HttpPost] 2 public HttpResponseMessage UpMessage([FromBody]UploadSmsDto body) 3 { 4 5 string message = "尊敬的经销商,您提交的兑换码已成功核销。感谢您的支持。【广汽菲克】"; 6 7 var response = Request.CreateResponse(HttpStatusCode.OK); 8 response.StatusCode = HttpStatusCode.OK; 9 response.Content = new StringContent(message); // 响应内容 10 return response; 11 }
参考:
【HttpResponseMessage】http://www.it165.net/pro/html/201305/6019.html
【FromBody】http://www.cnblogs.com/babycool/p/3922738.html