我想从网络服务下载文件。我试过这样做,但我无法在高级休息客户端中测试它。这是我的代码
public static HttpResponseMessage FileAsAttachment(string path, string filename)
{
if (File.Exists(path))
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(path, FileMode.Open);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
result.Content.Headers.ContentDisposition.FileName = filename;
return result;
}
return new HttpResponseMessage(HttpStatusCode.NotFound);
}
我总是有响应 " "$id": "1" "Message": "No HTTP resource was found that match the request URI ' http://localhost:36690/api/Data/FileAsAttachment?path=F :\&filename= claim.jpg'。" "MessageDetail": "在控制器 'Data' 上找不到与名称 'FileAsAttachment' 匹配的操作。" 我的控制器名称是 data