2013-09-05 3 views
1

HTTP 리디렉션이 발생하면 Chrome이 교차 원점 AJAX 요청을 취소하는 신비한 문제가 있습니다. 네트워크 탭에서 "(취소됨)"으로 표시되며 응답 헤더 또는 본문을 사용할 수 없습니다.리디렉션시 Chrome에서 CORS XHR을 취소합니다.

  1. 로드 페이지 HTTP에 :

    여기 흐름이다 //

  2. POST 요청은 HTTPS에 엔드 포인트 로그인 : //
  3. 303 응답 취소
  4. 요청.

    var r = new XMLHttpRequest(); 
    r.open('POST', 'https://dev.example.com/appName-rest/login', true); 
    r.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 
    r.send(JSON.stringify({"username":"myusername","password":"myrealpassword"})); 
    r.send(); 
    

    크롬의 순 내부 서버가이 헤더로 응답 하였음을 보여줍니다 : 여기

이 (ajaxtest.html에서)이 JS의

HTTP/1.1 303 See Other 
Date: Thu, 05 Sep 2013 17:54:21 GMT 
Server: Apache/2 
Access-Control-Allow-Origin: http://dev.example.com 
Access-Control-Allow-Credentials: true 
Location: https://dev.example.com/appName-rest/j_spring_cas_security_check?ticket=xxxx.example.com 
Vary: Accept-Encoding,User-Agent 
Content-Encoding: gzip 
Content-Length: 52 
Connection: close 
Content-Type: text/plain; charset=UTF-8 

그리고는 말한다 : URL_REQUEST_BLOCKED_ON_DELEGATE

합니까 왜 이것이 실패하고 있는지 아는 사람이 있습니까?

+0

WebService를 사용하고 있습니까? – PabloWeb18

+0

잘 모르겠다. 나는 그렇게 생각한다. 그러나 코드는 단순한 자바 스크립트입니다. –

답변

2

당신이 Cross-Origin Request with Preflight을하려고하는 것 같아 시도하십시오 때문에 당신이 설정 '콘텐츠 유형': '응용 프로그램/JSON'. 리디렉션이있는 프리 플라이트 된 요청은 CORS specs에 의해 거부됩니다.

0

이 방법을 두 번 보내고 있습니다. r.send();

은 다음

var xhr = new XMLHttpRequest(); 
    xhr.open("POST", "YOUR_URL", true); 
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 

    xhr.onreadystatechange = function (event) { 
     if (xhr.readyState === 4 && xhr.status === 200) { // if complete and success 
      return xhr.responseText; 
     } 
    }; 
    xhr.withCredentials = true; // OPTIONAL : I don't know if you need it for CORS Requests 
    xhr.send("username=YOUR_USERNAME&password=YOUR_PASSWORD"); 
관련 문제