我正在尝试向HTTP请求添加自定义头,但AngularJS似乎无法处理它。这是我的代码:
我尝试将其添加到默认标头,但仍然没有任何效果。这里出了什么问题?
编辑: 我在进行GET请求时发出请求:
$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)
headers
参数(参数为data
、status
、headers
、config
)。 - Eliran MalkaX-
前缀现已被弃用(http://tools.ietf.org/html/draft-ietf-appsawg-xdash-05)。为什么不改用标准的`Authorization`头部呢? - Eliran Malka