2

我将 Swashbuckle.Core 与 Asp.Net 一起使用,为我的 API 返回一个 IHttpActionResult。问题是 Swagger 中的响应返回的响应代码为 0,响应正文没有内容,但是当我通过邮递员进行相同的调用时,我重定向到的图像被返回并且响应代码为 200(这是我的行为想)。

招摇允许这样的重定向吗?是否有我缺少的设置或有关如何解决此问题的任何其他建议?

我返回的 IHttpActionResult:

public class ImageResponse : IHttpActionResult
    {
        private readonly string filePath;

        public LegacyImageResult(string filePath)
        {
            this.filePath = filePath;
        }

        private HttpResponseMessage Execute()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Redirect);

            try
            {
                if (filePath == null)
                {
                    return new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Image not found.") };
                }
                response.Headers.Location = new Uri(filePath);
            }
            catch
            {
                response.Dispose();
                throw;
            }

            return response;
        }
    }

编辑:

看起来这是一个已知的 Swagger 问题 https://github.com/swagger-api/swagger-ui/issues/549

4

0 回答 0