2016-07-28 4 views
0

수 없습니다 HTTPS를 XMLHttpRequest 요청을 할 것을 요청 -이 돌아 가지 :없음 '액세스 - 제어 - 허용 - 원산지'HTTPS에 대한 헤더

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:8443' is therefore not allowed access.

을 내가 www.google.com와 함께 URL을 교체하는 경우, 그것은 괜찮지 만 https://www.google.com 똑같은 일을합니다.

Postman/JaSON Chrome 확장 프로그램을 사용할 때 작동하므로 open -a Google\ Chrome --args --disable-web-security을 시도했지만 작동하지 않았습니다.

let request = new XMLHttpRequest(); 
request.open("POST", "https://outlook.office365.com/EWS/Exchange.asmx", true); 
request.setRequestHeader("Authorization", "Bearer " + asyncResult.value); 
request.setRequestHeader("Content-type", "text/xml; charset=utf-8"); 
request.setRequestHeader('Access-Control-Allow-Origin', '*'); 
request.setRequestHeader("Access-Control-Allow-Headers", "Content-type, Origin"); 
request.setRequestHeader("Access-Control-Allow-Methods", "POST"); 
request.onload = function() { 

}; 
request.onerror = function() { 
    debugger; 
} 
request.send(requestBody); 
+0

서버가 JavaScript가 아닌 COR을 설정합니다 – epascarello

+1

'outlook.office365.com'이 (가) 귀하의 도메인이 아니라고 추측하고 보안상의 이유로 크로스 기점 아약스를 수행 할 수 없습니다. ** 서버 **가 CORS 헤더) *. – adeneo

+0

@adeneo 네, 지금은'localhost'에서 왔지만 여전히'outlook.office365.com'에게 데이터를 가져 오기 위해 요청을 보내야합니다. – Kristin

답변

0

"Access-Control-Allow-Origin"헤더는 보안상의 이유로 서버 쪽에서 설정됩니다. 당신은 당신이 단지 수있는 서버에 액세스 한 경우

는 :

header("Access-Control-Allow-Origin: *"); 

이를하지만, 분명한 이유 안전하지 않습니다. 가능한 한 최소한의 외부 액세스 만 허용해야합니다.

최근에 같은 문제가있었습니다. 내가 한 일은 내 서버를 사용하여 API에서 요청을 보내고 대신 스크립트가 내 서버에 요청하도록합니다 (액세스 제어 헤더를 설정할 수 있음). 그래서 기본적으로 제 3 자의 클라이언트 측 (자바 스크립트에서)에게 요청을 보내는 대신 서버 쪽에서 만든 다음 자바 스크립트를 통해 서버에서 해당 데이터를 가져옵니다.

관련 문제