我已检查了一些链接,以了解错误原因但未解决我的问题。
我正在尝试从Postman访问WebAPi操作,但收到以下错误。
" message":"未找到与请求URI匹配的HTTP资源' http://localhost:50684/api/albums/history'。",& " messageDetail":"未找到与名为' 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}
在接到邮递员的电话时,我正在通过: -
任何帮助/建议都非常感谢。 感谢
答案 0 :(得分:6)
您是否在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
}
答案 1 :(得分:0)
您的代码应该是这样的:
[Authorize]
public class AlbumsController : ApiController
{
[HttpGet]
[Route("api/albums/history/")]
public IHttpActionResult GetHistory(string type,int id)
{
//api stuff
}
}
来自Postman的电话应该是这样的,并确保你在Postman中的方法是GET:
希望它会对你有所帮助。答案 2 :(得分:0)
我遇到了同样的问题,只是改变了这个问题:
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);
}