我敢打賭,這不是最好的解決方案,但它現在正在爲:
public class MyCustomFormatter : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
HttpResponseMessage response = actionExecutedContext.Response;
var contentType = response.Content.Headers.ContentType;
var oldContents = response.Content.ReadAsStringAsync().Result;
oldContents = oldContents.Replace("string", "myelement");
response.Content = new StringContent("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + oldContents);
response.Content.Headers.ContentType = contentType;
actionExecutedContext.Response.Content = response.Content;
}
}
您要自定義從網絡API發送XML? – 2013-02-22 15:13:17
嗨,是的,我正在尋找一種更簡單的方式來返回像第一個片段的自定義XML。 – 2013-02-23 23:09:52