【发布时间】:2018-11-04 05:06:23
【问题描述】:
我正在尝试从邮递员调用 WEBAPI。我的 AI 方法是 post,但是当我执行它时,我得到以下给定错误
找到多个与请求匹配的操作:***
以下是我的代码: webapi route.config
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "Api Default",
routeTemplate: "api/{controller}/{method}/{id}",
defaults: new { id = RouteParameter.Optional }
);
//config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
// Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
// To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
// For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
config.EnableQuerySupport();
// To disable tracing in your application, please comment out or remove the following line of code
// For more information, refer to: http://www.asp.net/web-api
config.EnableSystemDiagnosticsTracing();
}
}
API控制器:
public class MembershipController : ApiController
{
[System.Web.Http.ActionName("Upload")]
public HttpResponseMessage Upload(string employeedetails)
{
`Some Code`
}
[System.Web.Http.ActionName("BulkUpload")]
[System.Web.Http.HttpPost]
public HttpResponseMessage BulkUpload(string employeedetails)
{
`Some Code`
}
[System.Web.Http.ActionName("Transfer")]
public HttpResponseMessage Transfer(string employeedetails)
{
`Some Code`
}
}
我没有得到什么是错误的方法具有不同的操作名称,并且路由配置也是完全限定的 api url,其中包含控制器方法和 id 作为可选参数。要识别 url,这应该足够了,但它不起作用。 我错过了什么吗?
【问题讨论】:
-
这方面也有很多东西> stackoverflow.com/questions/14534167/…
-
所以
{method}应该是{action}@RobA? -
@Pavan this 工作还是你还有问题?
-
@win 这个问题还没有解决。但是我观察到的是当我在查询字符串中传递数据时它可以工作,但不幸的是查询字符串有大小限制,我的数据不止于此。当我使用httpcontext.Current.Request.Form.GetValue(0);我以字符串格式获取值,但我希望它在方法参数中,而不是在方法中编写代码来获取它。如何做到这一点?
标签: c# .net asp.net-web-api2