我试图在WildFly 8.2上从Angular2.1.0到JAAS基于表单的j2ee应用程序进行身份验证
let j_username = 'sb2'; let j_password = 'sb222'; let url: string = 'http://127.0.0.1:8888/prototype-rest/j_security_check'; let body = 'j_username=' + j_username + '&j_password=' + j_password; let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' }) ; //let options = new RequestOptions({headers: headers, withCredentials : true}); let options = new RequestOptions({headers: headers}); this.http.post(url, body, options) .subscribe( (res: Response) => { console.log('res = ' + res); console.log(res.headers.keys()); var headers = res.headers; var setCookieHeader = headers.get('Set-Cookie'); console.log('setCookieHeader = ' + setCookieHeader); }, err => { console.log('err = ' + err); } ) ;
来自wildfly的反应
HTTP/1.1 200 OK Expires: 0 Cache-Control: no-cache, no-store, must-revalidate X-Powered-By: Undertow/1 Set-Cookie: JSESSIONID=iyD6Yz_Tj7xsIM1zRDHaR2bh.sk-za-04702; path=/prototype-rest Access-Control-Allow-Headers: accept, authorization, content-type, x-requested-with Server: WildFly/8 Pragma: no-cache Access-Control-Expose-Headers: Set-Cookie Date: Thu, 03 Nov 2016 14:01:41 GMT Connection: keep-alive Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Content-Length: 0 Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT Access-Control-Max-Age: 3600
我的问题是我无法读取Set-Cookie,如果我使用withCredentials:true(我不确定是否应该),响应失败...我想将JSESSIONID添加到请求中,我在哪里注册websocket ......