The requested resource does not support http method 'OPTIONS'.?

前端 未结 6 1288
青春惊慌失措
青春惊慌失措 2020-12-06 01:43

I am making the following request to an asp.net web api PUT method from my angular.js client:

var org = {
                  OrgId: 111,
                  nam         


        
6条回答
  •  醉梦人生
    2020-12-06 02:08

    I know this is an old question, but I ran into the same problem and figured I could help others who are trying to figure out.

    I solved it by removing 2 of the handler configurations in the Web.config:

    
      
      
      
      
    
    

    I don't know exactly why it fixed the problem, but my working theory is that makes OPTIONS requests forbidden by default. When sending the request from a browser, it sends an OPTIONS request first before the PUT request, so it never gets to the PUT request because the first OPTIONS request was denied as an invalid http method on the api.

    In fiddler, I am assuming that it just sends only the PUT request (I observed the same behavior using the Postman web app sending requests manually). So it skips the forbidden OPTIONS request and succeeds.

提交回复
热议问题