- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个基本的 Web API,它试图返回作为下载操作而不是数据流触发的 Excel 文档。我在网上遵循了许多有关创建流和设置附件属性的示例,但我的 postman 请求始终显示为已编码。下面是API方法。
[Route("getexcel")]
[HttpPost]
public async Task<IHttpActionResult> GetExcel()
{
IHttpActionResult result = null;
FileInfo newFile = new FileInfo(@"C:\Test.xlsx");
ExcelPackage pck = new ExcelPackage(newFile);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new ByteArrayContent(pck.GetAsByteArray());
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.Content.Headers.ContentDisposition.FileName = "Test.xlsx";
result = ResponseMessage(response);
return result;
}
从上面的代码中,如果我使用 MediaTypeHeaderValue("application/pdf"),则 Postman 请求会显示下载请求,但对于 xlsx 格式或 application/octet-stream 则不会。相反,它显示数据流。 Content-Type 是 application/json,因为最终版本的 api 将在正文中获取 json 数据。
最佳答案
关于excel - 使用 EPPlus 返回 Task<IHttpActionResult> 中的 xlsx 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45426554/
我见过的大多数 Web API 2.0 方法都返回 IHttpActionResult ,它被定义为“定义异步创建 System.Net.Http.HttpResponseMessage 的命令”的接
我有一个 Web API Controller ,其方法类似于(截断不相关的位): [HttpGet] public IHttpActionResult Order(int orderId) {
我正在尝试在 Web API 2 中创建一个自定义 IHttpActionResult 类型,它将以 HTML 而不是 json 的形式返回内容。我正在努力解决的问题是如何对返回我的新 ActionR
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以
我目前正在研究Asp.net WebAPI2项目。我正在制作一个用于返回自定义HttpStatusCode进行错误处理的自定义方法。 这是我的代码 public IHttpActionResu
我创建了一个ASP.NET Web API,它将调用Java Web服务并以JSON显示一些结果。当Java Web服务未运行时,我收到以下错误消息: {"Message":"An error has
我正在使用 .NET Core 2 创建一个 API,为使用不同技术开发的许多应用程序提供数据。我目前正在从我的方法返回 IActionresult。我一直在研究返回数据的最佳选择是什么,并看到了一些
我已经确定了这些预定义的响应: Ok - 200 NotFound - 404 Exception - 500 Unauthorized - 401 BadRequest - 400 Conflict
我正在尝试编写一个通用方法以使用我的 Web API 2 返回内部服务器错误... 当我的 Web API 的每个端点发生错误时,我返回一个 InternalServerError(new Excep
我创建了一个基于 ASP.NET Web API 的应用程序并遵循以下教程: http://www.asp.net/web-api/overview/getting-started-with-aspn
我正在做一个演示,并弄清楚如何以与我们创建时相同的方式最好地执行 IHttpActionResults,好的,现在在 Web API 2 中使用 badrequest。 [Route("dem
这个问题在这里已经有了答案: When to return IHttpActionResult vs Object (2 个答案) 关闭 6 年前。 在使用 API 时,我通常将它们写在从 IHtt
我是 ASP.NET webapi 的新手,我找不到返回按 id 查询的对象列表的方法。 这是我的 GET 请求的 Controller 方法。我想返回所有具有通过 url 传递的指定 questio
我正在为我的网站开发 Web API,但遇到了问题。 目前,API 应该返回指定用户的详细信息。 这是我的帐户 Controller : using System; using System.Coll
这样做是可能的,但并不理想:(一个大大简化的例子!) [Serializable] public class MyRecord { public string key {get; set;}
如何返回 HttpError(自己的、格式漂亮的前端错误消息)然后使用方便的 IHttpActionResult? public IHttpActionResult Delete(Guid id) {
我正在尝试使用 Ihttpstatus header 获取此 JSON 响应,该 header 声明代码 201 并将 IHttpActionResult 保留为我的方法返回类型。 我要返回的 JSO
我正在尝试为我们的一些 webapi 调用创建一个测试,但我在访问结果时遇到了困难。在我看到的所有示例中,他们都使用 OkNegotiatedContentResult。问题是在我们的 web api
在使用 ASP.NET Web API 的示例中,我看到两种不同的方法用于将数据返回给调用 jQuery 函数。第一个方法返回 Client 类型的对象,但我不确定第二个方法返回什么。 方法 #1(返
有没有一种方法可以使用新的 IHttpActionResult 接口(interface)返回 HttpStatusCode.NoContent 响应消息? 我目前正在使用 return new Ht
我是一名优秀的程序员,十分优秀!