【发布时间】:2016-04-06 13:05:38
【问题描述】:
当我使用具有 special char 的字符串参数调用 webapi2 GET 时,我的问题出现了(正常字符都可以正常工作)。
AngularJs
this.getByContactValue = function (contactValue) {
return $http.get("/api/subjects/"+ contactValue+ "/ContactValue" );
}
c#
[Route("api/subjects/{contactValue}/ContactValue")]
public IEnumerable<Subject> GetByContactValue(string contactValue)
{
return repository.GetByContactValue(contactValue);
}
响应是 404 错误。 我也试过用这种方式修改请求
this.getByContactValue = function (contactValue) {
var request = $http({
method: "get",
url: "/api/subjects/ContactValue", //modified the route in c# controller
data: contactValue
});
return request;
}
但错误是一样的。
调用 webapi 的最佳方式是什么?
【问题讨论】:
-
最好的方法是在查询字符串或表单中传递参数。您能否提供发生错误的数据?
标签: c# angularjs asp.net-web-api asp.net-web-api2