壞請求400 Asp.net網頁API這裏是我的配置和代碼。的Http在MVC4
public class DeployLogController : ApiController
{
// GET /api/DeployLog
public List<DeployLogModel> Get(Guid deployDetailId, Guid? deployLogId)
{
DeployLogService service = DeployLogService.Instance;
return service.GetNewestDeployLogs(deployDetailId, deployLogId).ToList();
}
// POST /api/DeployLog
public void Post(DeployLogModel deployLogModel)
{
DeployLogService service = DeployLogService.Instance;
service.SavaDeployLogByServer(deployLogModel);
}
}
以及Global.asax.cs中Application_Start的代碼如下。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Login", action = "Login", id = UrlParameter.Optional }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
BundleTable.Bundles.RegisterTemplateBundles();
Configure(GlobalConfiguration.Configuration);
}
爲什麼我得到了400的HTTP響應消息。當我訪問的URL的 「http://本地主機:8119/API/DeployLog」。似乎代碼
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
不起作用。我想念什麼?請幫幫我 。謝謝。
不確定?HTTP 400傾向於通過直接或HTTP.SYS IIS中產生的,通常是由於錯誤的HTTP請求引起的。如果路由是失敗,那麼你會只是得到一個HTTP 404這是阿爾斯o可能他使用不支持的HTTP動詞。我認爲OP應該在另一個服務上測試他的WebAPI客戶端,或者用桌面瀏覽器測試他的WebAPI。 – Dai 2012-07-30 03:46:08
不錯。這是有幫助的 – 2012-08-05 09:50:40