本地主机请求标头不发送cookie

我正在构build一个nodeJS服务器,它允许用户使用客户端应用程序上的AJAXpost进行login。 服务器响应一个cookie,成功login后,跟踪用户。 我似乎不能让客户端应用程序发送cookie回服务器。 它似乎从来没有回应包括刚刚收到的cookie的服务器。

在对服务器进行的第一次通话中,我使用凭证login。 服务器回应这个:

在响应标题中:

Set-Cookie:SID=0xtW36rYCiV; path=/; expires=Tue, 24-Jun-2014 14:14:51 GMT; secure 

在随后的请求头中:没有cookie被发送回服务器

在我的客户端应用程序中,我使用下面的代码:

 jQuery.ajax( { url: this.domain + this.url, async: this.async, type: 'POST', dataType: this.dataType, crossDomain: true, cache: true, accepts: 'text/plain', data: this.postVars, success: this.onData.bind( this ), error: this.onError.bind( this ), xhrFields: { withCredentials: true } }); 

注意我正在使用xhrFields。

而在我的节点服务器,我正在回应这个:(注意我包括所有的CORRSvariables)

 if ( request.headers.origin ) { if ( request.headers.origin.match( /mydomain\.net/ ) || request.headers.origin.match( /appname\.mydomain\.com/ ) || request.headers.origin.match( /localhost/ ) || request.headers.origin.match( /localhost\.com/ ) || request.headers.origin.match( /localhost\.local/ ) || request.headers.origin.match( /localtest\.com/ ) ) { response.setHeader( 'Access-Control-Allow-Origin', request.headers.origin ); response.setHeader( 'Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS' ); response.setHeader( 'Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With' ); response.setHeader( "Access-Control-Allow-Credentials", "true" ); }; } response.writeHead( 200, { "Content-Type": "application/json" }); response.end( JSON.stringify( json ) ); } 

我还编辑了我的Windows主机文件,以包含这些testing域,以便我不必使用IP或localhost iteself:

 127.0.0.1 localhost 127.0.0.1 tooltest.com 127.0.0.1 localhost.com 127.0.0.1 localhost.local 

但是无论我做什么,或者我使用了哪个上面的主机,它似乎都不起作用。 它似乎只通过ajax与本地主机有关,因为如果我直接进入服务器url问题 – 它的作品。

编辑1

所以例如 – 我打开客户端应用程序,并尝试login到foo.com/user/log-in服务器。 请求和响应的标题如下所示:

请求:

 Remote Address:188.xxx.xxx.xx:7000 Request URL:https://foo.com:7000/user/log-in Request Method:POST Status Code:200 OK Request Headersview source Accept:undefined Accept-Encoding:gzip,deflate,sdch Accept-Language:en-GB,en-US;q=0.8,en;q=0.6 Connection:keep-alive Content-Length:45 Content-Type:application/x-www-form-urlencoded; charset=UTF-8 Host:foo.com:7000 Origin:http://localhost Referer:http://localhost/animate-ts/trunk/bin/ User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 Form Dataview sourceview URL encoded user:mat password:testpassword rememberMe:true 

响应:

 Response Headersview source Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:Content-Type, Authorization, Content-Length, X-Requested-With Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS Access-Control-Allow-Origin:http://localhost Connection:keep-alive Content-Type:application/json Date:Tue, 24 Jun 2014 14:14:21 GMT Set-Cookie:SID=0xtW36rYCiV; path=/; expires=Tue, 24-Jun-2014 14:14:51 GMT; secure Transfer-Encoding:chunked 

正如我所说的,Foo.com已经告诉浏览器存储cookie 0xtW36rYCiV。 但是,当我做下一个请求(foo.com/user/is-logged-in)来查看用户是否已经login,没有cookie发送到foo。 Foo.com使用ID 0xtW36rYCiV查找cookie,但找不到任何内容。 当我看到开发工具中的第二个请求时,我可以看到:

在这里输入图像描述

有没有人有任何其他的想法? 我以为我在上面覆盖了一切,但即时通讯开始认为它只是不会工作:(

谢谢你