Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web Api: The requested resource does not support http method 'GET'

I've got the following action on an ApiController:

public string Something() {     return "value"; } 

And I've configured my routes as follows:

routes.MapHttpRoute(     name: "DefaultApi",     routeTemplate: "api/{controller}/{action}/{id}",     defaults: new { id = RouteParameter.Optional } ); 

In the beta, this worked just fine, but I just updated to the latest Release Candidate and now I'm seeing errors on calls like this:

The requested resource does not support http method 'GET'.

Why doesn't this work anymore?

(I suppose I could get rid of {action} and just make a ton of controllers, but that feels messy.)

like image 907
Josh Schultz Avatar asked Jun 12 '12 22:06

Josh Schultz


People also ask

How do I fix the requested resource does not support HTTP method GET?

Simply changing the URL scheme of my request from HTTP to HTTPS fixed it.

What is Acceptverbs in Web API?

AcceptVerb is one attribute of the Web API actions. We can use it to allow a specific HTTP verb in a Web API action. Have a look at the following example. In this example we will allow both of the GET and POST verbs to do certain actions in the Web API.

Does not support HTTP method options?

If your javaScript is Http PUT or DELETE, you will find this error, The requested resource does not support http method 'OPTIONS'. Most of the browser will send a Preflight Request before it sends the actual request. One of the conditions to skip the Preflight Request is “The request method is GET, HEAD, or POST”.


1 Answers

If you have not configured any HttpMethod on your action in controller, it is assumed to be only HttpPost in RC. In Beta, it is assumed to support all methods - GET, PUT, POST and Delete. This is a small change from beta to RC. You could easily decore more than one httpmethod on your action with [AcceptVerbs("GET", "POST")].

like image 145
dinesh ravva Avatar answered Oct 10 '22 01:10

dinesh ravva