No http resource was found that matches the request uri
No http resource was found that matches the request uri
Why is it that «No HTTP resource was found that matches the request URI» here?
I have code in my controller like so:
. and I’m calling it via Postman like so:
UPDATE
Yes, it apparently has nothing to do with it being a Post and passing args in the URI, because I’m getting the same thing now with an HttpGet method:
I’m calling it from postman like so:
. and it does indeed appear in my controller:
UPDATE 2
I thought I was about to solve it when I changed this code:
. but I still get the same err msg.
UPDATE 3
I find that this also is not working:
. and so there is a definite pattern. EVERY REST API call I make that contains args/params fails in this same way; all of the others ( http://localhost:21609/api/deliveries/Count, http://localhost:21609/api/deliveryitems/count, http://localhost:21609/api/department/getall ) work just fine. IOW, if there are no args in the URI, the method is discovered. If there are args, it is not.
So apparently there’s either something wrong with how I’m passing the args/vals in the URI (appending «?=» in the case of a single arg and, in the case of two args «?=&=«) and/or there’s something wrong with how I set up the routing. Specifically, this style works:
. whereas this style does not:
UPDATE 4
I changed the routing to include the data type of the arg so that this:
But it still failed, growling:
Then, «on a lark,» I tried entering this into Postman:
. and it worked! (I had been thinking it needed to be » http://localhost:21609/api/delivery/invnumbyid?ID=45 «)
But a similar attempt in Postman:
. continues to fail with «No value given for one or more required parameters.» even though this is hit:
. and the args to GetNDepartmentsFromID() has the expected vals (2 and 12)
Even worse/weirder is the result I get with » http://localhost:21609/api/deliveryitems/InsertIntoPPTData/serNum77;tx2;siteNum2;bla2.xml;ppt_user2;tx_memo2;file_beg2;file_end2 » now:
I sadly smilingly remember that there is always one more gargoyle hiding behind the rustling curtain (where Robinson Jeffers and Edgar Allen Poe are seemingly wrestling). Palely loitering.
UPDATE 5
Okay, here it is stated differently:
From Postman, if I use this URL:
I make it into this method:
. where the value of FirstId is 2, and the value of CountToFetch is 12 (as I would expect them to be). But then, Postman sends back my package with the notation, «500 No value given for one or more required parameters.«
¡Que demonios! Both parameters were obviously passed!
If I use a URI that would seem more correct:
Yet this is the route that I’ve provided:
. and so I would say that I did, in fact, provide a matching action on the controller.And, BTW, if I just enter this as the URI into Postman:
. and then use Postman’s «URL Parameter Key / Value» interface to add those, it generates the exact same URL as above, as can be seen here:
. and with the exact same result.
I can only say it again (pardon my «Las Uvas de la Ira«-inspired Spanish): ¡Que demonios!
12 Answers 12
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Let’s go back to two very simple working examples.
The first sample says that the » anyString » is a path segment parameter (part of the URL).
First sample example URL is:
The second sample says that the » anyString » is a query string parameter (optional here since a default value has been provided, but you can make it non-optional by simply removing the default value).
Second sample examples URL are:
Of course, you can make it even more complex, like with this third sample:
Third sample examples URL are:
When should you use path segment or query parameters? Some advice has already been given here: REST API Best practices: Where to put parameters?
No HTTP resource was found that matches the request URI in Web API
I have configured my WebApiConfig like this:
This gives me an error: No HTTP resource was found that matches the request URI ‘http://localhost:8598/api/WebApi/GetLocationCategory/87’
4 Answers 4
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Try changing your Controller method as
Edit :
Its a long time when I look back I think I know the reason now. Words Like Jared is correct, it’s all to do with Routing which we specify. If I have a route(default) as :
Similarly, if I want to change my parameter name for Id to say CatId, then I need to change the query string parameter(the way I am calling my Controller Action would change). Which would now be :
public IEnumerable GetLocationCategory(int id)
This is a good default as it matches the convention.
Alternatively, you can modify the route to use this unconventional parameter name instead:
The URL should be
Note:- If your action name is GetIndex then the URL must be GetIndex not just Index. Optionally you can specify the [HttpGet] attribute for the action.
If you have the following as well in your WebApi.config
Then http://localhost:58432/api/foo?Id=1 would also be a legitimate route. Not sure if you would want that.
No HTTP resource was found that matches the request URI error in ASP.NET Web API
This is a sketch of my TransferController class.
All this is Web API code.
This is the routing.
This is the invocation.
And this is the result.
No HTTP resource was found that matches the request URI ‘http://localhost:54770/api/Transfer/Queue?sessiondId=0e2c47b9-e674-446d-a06c-ce16932f9580’.
This is a sketch of my UserController class.
For reasons unfathomable to me, I have no trouble calling anything in the UserController. Parameters are marshalled in exactly the same way, and the same routes are in use.
Darrel Miller below uses unit testing to validate routes. Frankly I’m kicking myself for not thinking of this, and now I’ve done the same.
But tests as he shows them really test only parsing of the URL. For example, this test passes
despite the conspicuous absence of a method Wibble on the Transfer controller.
Also the route object is not actually a HttpRoute object, it’s a HttpRouteData object. But that’s trivially corrected. The HttpRoute object is available as a property of the HttpRouteData object.
And it in turn has a Handler property. However this is less informative than it might be, since a null handler simply means (from MSDN)
If null, the default handler dispatches messages to implementations of IHttpController.
Now, my controller is derived from ApiController which certainly implements the ExecuteAsync method that is the only thing specified by the IHttpController interface. Which I imagine means I could test execution of that method if I knew more about it.
No HTTP resource was found that matches the request URI error in ASP.NET Web API
This is a sketch of my TransferController class.
All this is Web API code.
This is the routing.
This is the invocation.
And this is the result.
No HTTP resource was found that matches the request URI ‘http://localhost:54770/api/Transfer/Queue?sessiondId=0e2c47b9-e674-446d-a06c-ce16932f9580’.
This is a sketch of my UserController class.
For reasons unfathomable to me, I have no trouble calling anything in the UserController. Parameters are marshalled in exactly the same way, and the same routes are in use.
Darrel Miller below uses unit testing to validate routes. Frankly I’m kicking myself for not thinking of this, and now I’ve done the same.
But tests as he shows them really test only parsing of the URL. For example, this test passes
despite the conspicuous absence of a method Wibble on the Transfer controller.
Also the route object is not actually a HttpRoute object, it’s a HttpRouteData object. But that’s trivially corrected. The HttpRoute object is available as a property of the HttpRouteData object.
And it in turn has a Handler property. However this is less informative than it might be, since a null handler simply means (from MSDN)
If null, the default handler dispatches messages to implementations of IHttpController.
Now, my controller is derived from ApiController which certainly implements the ExecuteAsync method that is the only thing specified by the IHttpController interface. Which I imagine means I could test execution of that method if I knew more about it.
No HTTP resource was found that matches the request URI ‘http://localhost/api/GetById/2’
So many people have asked the same question but I couldn’t find a solution to my problem.
in postman when i call the ‘http://localhost/api/GetById/2’ i get the following error
No HTTP resource was found that matches the request URI http://localhost/api/GetById/2.
It works fine when I pass value 2 as a query string http://localhost/api/GetById/?id=2. Following is my WebApiConfig route parameter settings:-
Following is my my API controller action method
Will please someone tell me what i am doing wrong here?
2 Answers 2
Trending sort
Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.
It falls back to sorting by highest score if no posts are trending.
Switch to Trending sort
Change your route to:
You can also be very specific to tell the code where the id value is coming from by using the [FromRoute] attribute like the following:
Replace steve with the controller name. You are mixing attribute routing and convention based routing. That is causing the routetable to barf. Since you use the route
/api/getbyid/ it no longer has a controller reference from the convention based routing. So you need to do either all attribute routing or all convention based routing.
Источники информации:
- http://stackoverflow.com/questions/15715744/no-http-resource-was-found-that-matches-the-request-uri-in-web-api
- http://stackoverflow.com/questions/23013509/no-http-resource-was-found-that-matches-the-request-uri-error-in-asp-net-web-api
- http://stackoverflow.com/questions/23013509/no-http-resource-was-found-that-matches-the-request-uri-error-in-asp-net-web-api/23059333
- http://stackoverflow.com/questions/47755514/no-http-resource-was-found-that-matches-the-request-uri-http-localhost-api-ge




