2016-08-06 3 views
2

각도가 너무 작습니다.직각, 포스트, 삭제 반환 405

각도를 사용하여 POST, PUT 및 DELETE 메서드를 호출 할 수 없습니다. 모든 메서드와 모든 리소스 URL이 작동하고 Advanced Rest Client를 사용하여 테스트 한 .NET WebApi 서버가 있습니다.

$scope.updateUser = function() { 

    var url = 'http://localhost/api/users/' + $scope.selectedId; 
    $http.put(url, $scope.user,{'content-type' : 'application/json'}) 
     .then(
      function(response) { 
       alert("1"); 
      }, 
      function(errResponse) { 
       alert("2"); 
      } 
     ); 
}; 

내가 '콘텐츠 유형'으로 시도 :

코드는 '응용 프로그램이 X-형태-urlencoded로는 www /에서'나는 전혀 설정과 시도, 내가 가진 하나의 시도 성공과 오류 그리고 나는 whith 명령과 데이터 속성을 시도했다.

디버깅 중에 아무런 변화가 없으며 errResponse에는 요청 데이터 만 포함됩니다. 개발자 도구에서 네트워크 탭을 확인한 결과 405가 반환되었습니다. 다시 말하지만 모든 URL은 타사 REST 클라이언트 앱을 사용하여 유효하고 테스트되었습니다.

아무도 도와 줄 수 있습니까?

편집 : 의 Web.config :

<system.webServer> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> 
     <remove name="OPTIONSVerbHandler" /> 
     <remove name="TRACEVerbHandler" /> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> 
    </handlers> 
    <modules runAllManagedModulesForAllRequests="true"> 
    <remove name="WebDAVModule" /> 
    </modules> 
    <httpProtocol> 
    <customHeaders> 
     <add name="Access-Control-Allow-Origin" value="*" /> 
     <add name="Access-Control-Allow-Headers" value="Content-Type" /> 
     <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" /> 
    </customHeaders> 
    </httpProtocol> 
    </system.webServer> 

PUT 예 :

[HttpPut] 
    [Route("api/users/{id}")] 
    public IHttpActionResult updateUser(int id, User user) 

감사합니다, 이도

+1

global.asax의 일부 API 인 web.config를 공유하십시오. 당신은 벗어날 아주 적은 코드를주었습니다. –

+0

당신의'[HttpPut]'속성이'System.Web.Http'입니까? (System.Web.Mvc가 아님) –

+0

web.config를 추가하고 예 –

답변

0

는 Web.config의이 조각은 해결해야 부가하는 문제 :

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <remove name="WebDAVModule" /> 
    </modules> 
</system.webServer> 
+0

아니요.이 URL에 연결할 수 있습니다 ... 각도가 아닙니다. –