【问题标题】:How to tell web api ApiExplorer that the endpoint will return binary data (like a zip file)?如何告诉 web api ApiExplorer 端点将返回二进制数据(如 zip 文件)?
【发布时间】:2017-11-30 19:17:37
【问题描述】:

对于返回模型的端点,我们可以使用ResponseTypeAttribute 告诉帮助页面文档返回数据的样子:

/// <summary>
/// returns the specified Foo.
/// </summary>
[ResponseType(typeof(FooModel))]
[HttpGet]
[Route("~/api/foos/{fooId}")]
public async Task<IHttpActionResult> GetFoo(int fooId)
{
    ...
}

这将在 Api 帮助页面上创建一个很好的条目,描述此端点的行为方式。

我想记录某个端点将返回一个应用程序/zip 二进制流。我该怎么做?

【问题讨论】:

    标签: c# asp.net-web-api documentation asp.net-mvc-apiexplorer


    【解决方案1】:

    如果您已经知道您的 api 端点将返回 zip 文件,那么您可以将其硬编码为 application/octet-stream

    content-type = "application/octet-stream"
    

    【讨论】:

    • 硬编码在哪里?我特别希望将其显示在在线文档中。
    • 不是我希望的答案,但似乎是正确的答案。
    猜你喜欢
    • 1970-01-01
    • 2011-08-10
    • 2014-05-11
    • 2011-09-28
    • 2012-03-21
    • 2019-06-26
    相关资源
    最近更新 更多