这是我研究的用于实现从 Web api 下载文件的链接,我尝试使用这些 URL 下载文件
http://localhost:49932/api/simplefiles/1.zip <--不工作,抱怨找不到方法 http://localhost:49932/api/simplefiles/1 <--能够调用操作名称,但为什么?
我知道与导致失败的 URL 中的“.zip”扩展名有关,但我只是不明白,不确定出了什么问题,有人能解释一下吗?
界面
public interface IFileProvider
{
bool Exists(string name);
FileStream Open(string name);
long GetLength(string name);
}
Run Code Online (Sandbox Code Playgroud)
控制器
public class SimpleFilesController : ApiController
{
public IFileProvider FileProvider { get; set; }
public SimpleFilesController()
{
FileProvider = new FileProvider();
}
public HttpResponseMessage Get(string fileName)
{
if (!FileProvider.Exists(fileName))
{
throw new HttpResponseException(HttpStatusCode.NotFound);
}
FileStream fileStream = FileProvider.Open(fileName);
var response = new HttpResponseMessage();
response.Content = new StreamContent(fileStream);
response.Content.Headers.ContentDisposition
= …
Run Code Online (Sandbox Code Playgroud)