ASP.NET WebAPI 对PUT/DELETE的支持?
我的测试环境是Windows 10 pro + IIS10
我在这个环境上部署了一个 ASP.NET WebAPI 程序,在使用 Postman 进行测试发现对于 PUT/DELETE 都无法支持。
根据网上的描述,我把 web.config 改成如下
然后重新编译发布并 iisreset, 结果在Postman中仍是
试了很久,无解,求教各位大神指点一二...
(BTW, Postman会不会缓存请求?)
附:对应Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace WebLab1.Controllers
{
public class Member
{
public int ID { get; set; }
public string Name { get; set; }
}
public class DefaultController : ApiController
{
List<Member> _Members = new List<Member>(new Member[] {
new Member { ID = 1, Name = "Bruce S" },
new Member { ID = 2, Name = "Cindy K"},
new Member { ID = 3, Name = "Michael J"}
});
public IEnumerable<Member> Get()
{
return _Members;
}
public Member Get(int id)
{
return _Members.FirstOrDefault(m => m.ID == id);
}
public HttpResponseMessage Post(Member newMember)
{
_Members.Add(newMember);
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);
response.StatusCode = HttpStatusCode.Created;//201
string uri = Url.Link("DefaultApi", new {id = newMember.ID });//Related to route setting.
response.Headers.Location = new Uri(uri);
return response;
}
public HttpResponseMessage Put(int id, Member member)
{
var updateMember = Get(id);
updateMember.Name = member.Name;
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, updateMember);
string uri = Url.Link("DefaultApi", new { id = id });
response.Headers.Location = new Uri(uri);
return response;
}
public HttpResponseMessage Delete(int id)
{
_Members.Remove(Get(id));
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.NoContent);//204
return response;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,是Postman用错了...URL不对..
正确的URL应该是什么呀。我也测试不成功。。。