1

我正在尝试运行 PUT 和 DELETE 方法,但我得到 403 禁止响应。

$http({method: 'PUT', url: 'http.....', data: $scope.datos}).success(function(data){ .....};

我正在使用 TomEE(Tomcat),并配置了 web.xml(服务器)

  <servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
  <param-name>debug</param-name>
  <param-value>0</param-value>
</init-param>
<init-param>
  <param-name>listings</param-name>
  <param-value>false</param-value>
</init-param>
<init-param>
<param-name>readonly</param-name>
  <param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>

4

1 回答 1

1

通过将以下配置添加到 web.xml(服务器 TomEE)来更正:

 <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
  </init-param>
  <init-param>
    <param-name>cors.allowed.methods</param-name>
    <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value>
  </init-param>
  <init-param>
    <param-name>cors.allowed.headers</param-name>
    <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
  </init-param>
  <init-param>
    <param-name>cors.exposed.headers</param-name>
    <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
  </init-param>
  <init-param>
    <param-name>cors.support.credentials</param-name>
    <param-value>true</param-value>
  </init-param>
  <init-param>
    <param-name>cors.preflight.maxage</param-name>
    <param-value>10</param-value>
  </init-param>
于 2014-01-29T20:24:30.283 回答