2017-05-22 1 views
-1

이러한 레코드를 만들고 업데이트하기 위해 레코드와 폼이있는 표를 구현했습니다. 기록을 편집하고 나중에 그것을 저장할 때, 클라이언트는 다음과 같은 라인을 통해 이동합니다 :Tomcat 서버에 대한 ExtJS PUT 요청이 허용되지 않습니다.

var form = this.getView().getForm(); 
var record = form.getRecord(); 
record.beginEdit(); 
var updatedRecord = form.getValues(); 
record.set(updatedRecord); 
record.endEdit(); 

그렇게함으로써, 클라이언트는 신체 내부의 업데이트 된 매개 변수를 사용하여 Tomcat 서버에 PUT 요청을 보낼 것입니다.

내가 HTTP 요청을 전송하기 위해 브라우저 플러그인을 사용
<filter> 
    <filter-name>CorsFilter</filter-name> 
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> 
    <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> 
</filter> 
<filter-mapping> 
    <filter-name>CorsFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

우리는이 응답에서 볼 수 있듯이, 모든 것이 괜찮 :

Tomcat 서버는 web.xml에 설정된 모든 HTTP 메시지를 수

Status Code: 200 OK 
Allow: PUT 
Content-Language: en 
Content-Length: 190 
Content-Type: application/json 
Date: Mon, 22 May 2017 12:21:40 GMT 
Server: Apache-Coyote/1.1 

그러나 ExtJS로는 PUT 요청을 전송하면, 다음과 같은 응답을 얻을 :

HTTP/1.1 405 Method Not Allowed 
Server: Apache-Coyote/1.1 
Access-Control-Allow-Origin: http://localhost:1337 
Access-Control-Allow-Credentials: true 
Access-Control-Expose-Headers: Access-Control-Allow-Origin,Access-Control-Allow-Credentials 
Allow: DELETE,GET,OPTIONS 
Content-Type: text/html;charset=utf-8 
Content-Language: en 
Content-Length: 1056 
Date: Mon, 22 May 2017 11:55:37 GMT 

ExtJS가 PUT 요청을 보내면 tomcat이 PUT, GET 및 POST를 허용하지 않는 이유는 무엇입니까? 의 ExtJS가 POST 요청을 보낼 때, 모든 것이 잘 작동하고 나는 다음과 같은 응답을 얻을 :

Access-Control-Allow-Credentials:true 
Access-Control-Allow-Origin:http://localhost:1337 
Access-Control-Expose-Headers:Access-Control-Allow-Origin,Access-Control-Allow-Credentials 
Content-Length:225 
Content-Type:application/json 
Date:Mon, 22 May 2017 12:59:07 GMT 
Server:Apache-Coyote/1.1 

을 내가 PUT 메시지를 허용하기 위해 Tomcat을 얻으려면 어떻게해야합니까?

답변

0

EXTJS의 proxy 구성에 headers을 지정해야합니다.

proxy: { 
    headers: {'Content-Type': "application/json" } 
    ... 
} 

문제를 해결할 헤더를 지정하면됩니다.

나는 actionMethod도 문제를 만들 수 있다고 생각합니다. 기본적 extjs's store으로

GET 요청을 전송하지만, 당신이 PUT 요청을 보내려면 당신은 actionMethods 설정

proxy: { 
    actionMethods: { 
      read : 'PUT', 
      create : 'POST', 
      update : 'PUT', 
      destroy : 'DELETE' 
     } 
... 
} 

참조하십시오 link에 지정할 수 있습니다.

+0

그건 도움이되지 못했습니다. – Goldi

+0

서버가 기대하는 모든 헤더를 넣었습니까? 또는 백 엔드 요청 코드를 보여줄 수 있습니까? MediaType을 확인 했습니까? –

+0

최근 편집 된 답변을 참조하십시오. 이것이 도움이되기를 바랍니다. –