我想在我的ASP.Net Web API Controller中返回一个文件,但我的所有方法都返回HttpResponseMessage为JSON.
public async Task<HttpResponseMessage> DownloadAsync(string id)
{
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent({{__insert_stream_here__}});
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return response;
}
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中调用此端点时,Web API会返回设置HttpResponseMessage为HTTP Content Header 的as JSON application/json.