No HTTP resource was found that matches the reques

2019-05-01 11:56发布

I have checked some number of links to get understanding the cause of the error but not fixing my issue.

I am trying to access WebAPi action from Postman but getting the below error.

"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'."

My API.

[Authorize]
public class AlbumsController : ApiController
{

   [HttpGet]
   [Route("api/album/history/")]
   public BaseTO GetHistory(string type,int id)
   {  
      //api stuff
   }
 }

I tried with api/album/history/{anything}

While making call from Postman I am passing:-

  • Authorization Token
  • Type
  • Id

Any help/suggestion highly appreciated. Thanks

3条回答
Deceive 欺骗
2楼-- · 2019-05-01 12:32

Your Code should be like this:

[Authorize]
public class AlbumsController : ApiController
{

   [HttpGet]
   [Route("api/albums/history/")]
   public IHttpActionResult GetHistory(string type,int id)
   {  
      //api stuff
   }
 }

and your call from Postman should be like this and make sure your method in Postman is GET:

http://localhost:50684/api/album/history?type=test&id=1

hope it will help you.

查看更多
老娘就宠你
3楼-- · 2019-05-01 12:39

I had the same problem I just changed this :

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);

    }
查看更多
倾城 Initia
4楼-- · 2019-05-01 12:46

Have you enabled attribute routing in api config? config.MapHttpAttributeRoutes();

With your current route, you should hit it via query string http://localhost:50684/api/albums/history?type=test&id=1 and decorate the parameters with [FromUri]

[HttpGet]
   [Route("api/albums/history/")]
   public IHttpActionResult GetHistory([FromUri]string type,[FromUri]int id)
   {  
      //api stuff
   }

or to hit the api via route parameters - http://localhost:50684/api/albums/history/test/1

[HttpGet]
   [Route("api/albums/history/{type}/{id}")]
   public IHttpActionResult GetHistory(string type,int id)
   {  
      //api stuff
   }
查看更多
登录 后发表回答