2014-01-24 2 views
4

HTTP 요청에 사용자 정의 헤더를 추가하려고하지만 AngularJS가이를 처리하지 않는 것 같습니다. 여기에 내 코드가있다 :

$http({ 
    method: "GET", 
    url: 'http://localhost:8080/Schedule-service/login', 
    headers: { 
     'X-AUTHENTICATION': 'TRUE' 
    } 
}).success(function (response) { 
    $cookies[constants.TOKEN] = response.hash; 
}).error(function (data, status, headers, config) { 

}); 

나는 이것을 기본 헤더에 추가하려고 시도했지만 아무 것도 아니다. 여기서 뭐가 잘못 됐니?

편집 : 하고 GET의 중간에 내 요청 :

Request URL:http://localhost:8080/Schedule-service/login 
Request Headers CAUTION: Provisional headers are shown. 
Access-Control-Request-Headers:accept, x-authentication 
Access-Control-Request-Method:GET 
Origin:http://localhost 
Referer:http://localhost/ScheduleWebClient/ 
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)  Chrome/32.0.1700.76 Safari/537.36 

그리고 GET 후

:

Request URL:http://localhost:8080/Schedule-service/login 
Request Method:OPTIONS 
Status Code:200 OK 
Request Headersview source 

Request Headers: 

Accept:*/* 
Accept-Encoding:gzip,deflate,sdch 
Accept-Language:pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4 
Access-Control-Request-Headers:accept, x-authentication 
Access-Control-Request-Method:GET 
Connection:keep-alive 
Host:localhost:8080 
Origin:http://localhost 
Referer:http://localhost/ScheduleWebClient/ 
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)  Chrome/32.0.1700.76 Safari/537.36 

Response Headers: 

Access-Control-Allow-Headers:origin, content-type, accept, x-requested-with, sid, mycustom, smuser 
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS 
Access-Control-Allow-Origin:* 
Allow:GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH 
Content-Length:0 
Date:Fri, 24 Jan 2014 20:33:23 GMT 
Server:GlassFish Server Open Source Edition 3.1.2.2 
Set-Cookie:JSESSIONID=5f4fc0d1318a2e63cd1ca9170386; Path=/Schedule-service; HttpOnly 
X-AUTHENTICATION:* 
X-Powered-By:Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7) 
+0

성공 콜백에 보낸'headers' 매개 변수를 사용하여 시도에 볼 수 있어야합니다 서버가 X가 요청한-으로 받아 들일 것을 헤더

Access-Control-Allow-Headers:origin, content-type, accept, x-requested-with. 

참조 위. (매개 변수는'data','status','headers','config'입니다). –

+0

또한 HTTP 헤더'X-'접두사는 이제 삭제되었습니다 (http://tools.ietf.org/html/draft-ietf-appsawg-xdash-05). 왜 대신'Authorization' 헤더를 사용하지 않을까요? –

답변

0

그것은 당신이 CORS 요청 및 붙여 넣은 요청을 수행하고 보인다는 프리 플라이트 요청입니다 . 응용 프로그램은 포트 80에서 작동하지만 포트 8080에서 서비스를 호출하므로 CORS 교차점이 발생합니다. 응답에서는 헤더는 다음 요청

관련 문제