public HttpResponseMessage GetBMIForXml(HttpRequestMessage request) {//encoding="utf-8"才能接 Person p = new Person(); var xmlDoc = new XmlDocument(); xmlDoc.Load(request.Content.ReadAsStreamAsync().Result); var str = xmlDoc.InnerXml; XmlSerializer serializer = new XmlSerializer(typeof(Person)); using (StringReader reader = new StringReader(str)) { p = (Person)(serializer.Deserialize(reader)); } double bmi = HealthService.CalculateBMI(p); var resp = new HttpResponseMessage(HttpStatusCode.OK); resp.Content = new ObjectContent <double>(bmi, new XmlMediaTypeFormatter { UseXmlSerializer = true }); return(resp); }
public IHttpActionResult GetBMI(Person human) { double bmi = HealthService.CalculateBMI(human); if (bmi < 0) { return(NotFound()); } return(Ok(bmi)); }