找不到与请求 URI 匹配的 HTTP 资源
No HTTP resource was found that matches the request URI
我检查了一些链接以了解错误原因,但没有解决我的问题。
我正在尝试从 Postman 访问 WebAPI 操作,但出现以下错误。
"message": "No HTTP resource was found that matches the request URI 'http://localhost:50684/api/albums/history'.",
"messageDetail": "No type was found that matches the controller named 'album'."
我的API.
[Authorize]
public class AlbumsController : ApiController
{
[HttpGet]
[Route("api/album/history/")]
public BaseTO GetHistory(string type,int id)
{
//api stuff
}
}
我试过 api/album/history/{anything}
当我从邮递员那里打电话时,我路过:-
- 授权令牌
- 类型
- 编号
任何 help/suggestion 高度赞赏。
谢谢
你的代码应该是这样的:
[Authorize]
public class AlbumsController : ApiController
{
[HttpGet]
[Route("api/albums/history/")]
public IHttpActionResult GetHistory(string type,int id)
{
//api stuff
}
}
你从 Postman 调用的应该是这样的,并确保你在 Postman 中的方法是 GET:
http://localhost:50684/api/album/history?type=test&id=1
希望对您有所帮助。
您是否在 api 配置中启用了属性路由? config.MapHttpAttributeRoutes();
根据您当前的路线,您应该通过查询字符串 http://localhost:50684/api/albums/history?type=test&id=1
命中它并使用 [FromUri]
修饰参数
[HttpGet]
[Route("api/albums/history/")]
public IHttpActionResult GetHistory([FromUri]string type,[FromUri]int id)
{
//api stuff
}
或通过路由参数点击 api - http://localhost:50684/api/albums/history/test/1
[HttpGet]
[Route("api/albums/history/{type}/{id}")]
public IHttpActionResult GetHistory(string type,int id)
{
//api stuff
}
我有同样的问题,我只是改变了这个:
AllowInsecureHttp = true
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/api/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
AllowInsecureHttp = true
};
app.UseOAuthBearerTokens(OAuthOptions);
}
我检查了一些链接以了解错误原因,但没有解决我的问题。
我正在尝试从 Postman 访问 WebAPI 操作,但出现以下错误。
"message": "No HTTP resource was found that matches the request URI 'http://localhost:50684/api/albums/history'.",
"messageDetail": "No type was found that matches the controller named 'album'."
我的API.
[Authorize]
public class AlbumsController : ApiController
{
[HttpGet]
[Route("api/album/history/")]
public BaseTO GetHistory(string type,int id)
{
//api stuff
}
}
我试过 api/album/history/{anything}
当我从邮递员那里打电话时,我路过:-
- 授权令牌
- 类型
- 编号
任何 help/suggestion 高度赞赏。 谢谢
你的代码应该是这样的:
[Authorize]
public class AlbumsController : ApiController
{
[HttpGet]
[Route("api/albums/history/")]
public IHttpActionResult GetHistory(string type,int id)
{
//api stuff
}
}
你从 Postman 调用的应该是这样的,并确保你在 Postman 中的方法是 GET:
http://localhost:50684/api/album/history?type=test&id=1
希望对您有所帮助。
您是否在 api 配置中启用了属性路由? config.MapHttpAttributeRoutes();
根据您当前的路线,您应该通过查询字符串 http://localhost:50684/api/albums/history?type=test&id=1
命中它并使用 [FromUri]
[HttpGet]
[Route("api/albums/history/")]
public IHttpActionResult GetHistory([FromUri]string type,[FromUri]int id)
{
//api stuff
}
或通过路由参数点击 api - http://localhost:50684/api/albums/history/test/1
[HttpGet]
[Route("api/albums/history/{type}/{id}")]
public IHttpActionResult GetHistory(string type,int id)
{
//api stuff
}
我有同样的问题,我只是改变了这个:
AllowInsecureHttp = true
public void ConfigureAuth(IAppBuilder app)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/api/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
AllowInsecureHttp = true
};
app.UseOAuthBearerTokens(OAuthOptions);
}