ServiceStack and returning a stream

前端 未结 1 1314
孤街浪徒
孤街浪徒 2020-12-01 09:41

I have just started to use ServiceStack which is an amazing library.

However, I have a business requirement where we must return xml and json where the xml must be i

相关标签:
1条回答
  • 2020-12-01 10:26

    Yes returning an IHttpResult will allow you to control the exact payload, Content-Type and other HTTP Headers as you wish.

    Also you're not limited to returning a stream, i.e. you can use the HttpResult to return an xml string with a different Content-Type.

    Here are some links that better demonstrate what's possible with ServiceStack return types:

    • How ServiceStack supports plain C# string, binary, stream, IStreamWriter, etc return types
    • An example of using CORS to set global or per-service custom HTTP Headers
    • Different ways of returning an Image from a ServiceStack service
    • Multiple options for returning HTML

    You can also return a static File using a FileInfo object, with an optional parameter to return the file as an attachment which will prompt the user to download the file rather than attempt to view it in the browser with:

    return new HttpResult(new FileInfo("~/static-response.xml"), asAttachment:true);
    
    0 讨论(0)
提交回复
热议问题