小编Luk*_*z M的帖子

如何调用 URL 末尾带有点的 Web API 操作?

这是我研究的用于实现从 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)

asp.net asp.net-web-api2

5
推荐指数
1
解决办法
3435
查看次数

标签 统计

asp.net ×1

asp.net-web-api2 ×1