我只是想通过 Web API 将记录添加到数据库中。
我这样称呼它:
localhost/X/api/Awards/directors/add?awardTitleId=1&personId=10078261&nameId=1651&isOnBallot=1&whoEntered=0&whoChanged=0
路线:
routes.MapHttpRoute(name: "AddDirector", routeTemplate: "api/awards/directors/add/{id}", defaults: new
{
controller = "Awards", action = "addDirector"
});
控制器:
[HttpPost]
public void addDirector(int awardTitleId, int personId, int nameId, bool isOnBallot, string whoEntered, string whoChanged)
{
myConnection.Open();
var query = "INSERT INTO dbo.AWD_Directors (AwardTitleId, PersonId, NameId, IsOnBallot, WhoEntered, WhoChanged) VALUES (" + awardTitleId + ", " + personId + ", " + nameId + ", " + isOnBallot + ", " + whoEntered + ", " + whoChanged + ")";
var cmd = new SqlCommand(query, myConnection);
cmd.ExecuteNonQuery();
myConnection.Close();
}
当我尝试在 Fiddler 上执行此操作时:
../X/api/Awards/directors/add?awardTitleId=1&personId=10078261&nameId=1651&isOnBallot=1&whoEntered=0&whoChanged=0
我收到以下消息:
{"Message":"The requested resource does not support http method 'POST'."}
有人可以帮帮我吗?