Tag: cookies

使用CORS请求设置Cookie

我一直在试图解决这个问题几天。 在CORS请求上设置Cookie。 我见过有冲突的文章和答案,有人说,只要XHR请求将withCredentials设置为true,并且服务器发送适当的头文件,浏览器应该尊重Set-Cookie头文件。 不过,在我的testing中,情况并非如此。 示例代码: index.js(Node.js服务器) const http = require('http'); const fs = require('fs'); // Pretty colors const colors = { purple: '\033[95m', orange: '\033[93m', blue: '\033[97m', underline: '\033[4m', bold: '\033[1m', reset: '\033[0m' } const server = http.createServer(function (req, res) { //Console logs to verify what's getting hit. console.log(colors.purple + colors.underline + 'Hit it!' + […]

ElectronJS:如何从渲染的进程(浏览器窗口)操作cookie?

我能够从主进程(app.js)创build持久性cookie 码: const session = require('electron').session; const ses = session.fromPartition('persist:name'); debugger; // Query all cookies associated with a specific url. ses.cookies.get({}, (error, cookies) => { console.log(cookies); /// cookies values should be printed next time the applciation is launched. }); // Set a cookie with the given cookie data; // may overwrite equivalent cookies if they […]

Nodejs的res没有被定义在内部需求

对于我的api我想要一个单独的文件来设置一个cookie(使用cookieparsing器)。 但res或req不会传递给所需的文件… index.js app.get('/api/user/:username', function(req, res) { urlUsername = req.params.username; require('./set/cookie') }); 集/ cookie.js res.cookie('login_session', urlUsername) // returns 'res' not defined 正如你所看到的部分解决这个问题,我设置了urlUsername工作。 但肯定还有另一种方式:)? 谢谢

将cookie的值设置为模板文字?

我正在创build一个模板文字,如下所示: const someVar = 'hello' const str = ` Some random multiline string with string interpolation: ${someVar} ` 然后在我的Koa应用程序中,我正在做: this.cookies.set('str', str) 显然它不喜欢多行string,因为它给出了这个错误: TypeError:参数值无效 有没有办法解决? 保持空白格式对我来说是非常必要的。

节点JS浏览器模拟(cookies,会话,标题)

我需要像一个普通的浏览器从节点js请求。 我是什么意思? 我可以设置任何HTTP信息,如Cookie,标题,正文。 所以要build立HTTP请求,我想要的。 请求发出后,所有的响应数据应该是可读的,比如Set Cookie …. 如果可以在会话期间自动保存cookie,那将会很棒。 所以我不需要在每次进一步提出请求时都包含它们。 所以只需模拟一个真实的浏览器来保持会话 有没有任何框架的库可以提供这样的function?

Node.js cors req.headers.cookie?

我有一个node.js服务器来处理一些东西,它位于端口:9000 ,我build立了一个authentication中间件来限制一些路由。 虽然我不能获取cookie,所以我怀疑这是因为req来自另一个地方:3000例如:3000 。 我不是试图获取cookie的快递集,我试图从请求获得客户端的PHP cookie // using var req = http.IncomingMessage.prototype; req.authenticated = function(callback) { console.log(this.headers.cookie) } 所以问题是我怎样才能设置,以便每当:3000向我的node.js服务器发出请求:9000 cookie是与头一起发送?

如何获取js响应的angular度js中的数据(来自js中间件)

所以我正在手动创build令牌。 我想要做的是用户login后,令牌发送到JSON格式的angular度模块或其他一些格式无关紧要,然后我想保存在cookie中。 这里是来自节点js的一个简单的json响应代码 res.json({success : 1, token: "adhahashahd"}); 请现在指导我如何获取这个angular度控制器,然后如何保存这个angular度的cookie。 谢谢。 这是编辑的部分家伙 这是我调用节点js路由的控制器代码 $http.post('../userlogin', $scope.user).success(function(response) { console.log(response); 这是整个过程完成后由nodejs做出的响应 res.json({token : "asx"}); 现在这是我从下面给出的答案跟随的cookie部分。 $http.post('../userlogin', $scope.user).success(function(response) { console.log(response); $http.get('userlogin').success(function(data){ data=JSON.Parse(data); $cookie.put('token',data.token) }).error(function(error){ console.log(error) }) 这个错误出现在前端部分,就像谷歌浏览器的开发者窗口中看到的一样 GET http://localhost:1339/userlogin 404 (Not Found) 向上投票你们所有人,谢谢你们。 一个问题,如果所有的答案都足够好,我可以接受多个答案。 因为你们都给出了正确的build议。 我真的很感激。 🙂 编辑没有2个人 当我只是这样做 var z = response.token; console.log(z); $cookie.put('token', z); 我能够得到我想要的,但现在错误与cookie有关。 它读取 ReferenceError: $cookie […]

使用iisnode时保证CookieSession的安全

我通过使用iisnode与IIS使用节点,我有麻烦设置CookieSession选项secure:true 。 我在IIS上使用HTTPS,并将任何HTTPredirect到HTTPS。 但即使如此,如果我将cookieSession选项设置为secure:true ,那么login后会话将不会有任何内容。 secure:一个布尔值,指示cookie是否仅通过HTTPS发送(默认情况下为HTTP,HTTPS为默认情况下为true)。 我不得不使用secure:false来使其工作。 为什么?

Hapijs – 为所有请求添加cookie

使用Hapijs Node框架,我想确保每个请求都存在一个特定的cookie。 如果它不存在,我想创build它。 我想这样做,而不是手动添加该cookie到每个reply 。 例如,像这样的东西: server.ext('onPreHandler', function (request, reply) { console.log(`state: ${JSON.stringify(request.state)}`) // state == null request.state['my_cookie'] = request.state.my_cookie || 'my data' return reply.continue(); }); server.route({ method: 'GET', path: '/', handler: function(request, reply) { // includes `my_cookie` reply(`Cookies: ${JSON.stringify(request.state)}`); } }) // cookie does not exist in the browser 将该cookie添加到回复中,但需要在应用程序中添加每个回复。 server.route({ method: 'GET', path: […]

如何在NodeJS中设置cookie的到期时间?

我正在写我自己的cookies作为我使用NodeJS(即不使用任何软件包)的networking服务器的一部分。 我已经能够做到这一点使用像这样的事情: response.writeHead(200, { 'Set-Cookie':'sesh=wakadoo' }); 不过,我想让我的cookies比现在更持久(也就是说根本就不说)。 我试过做这样的事情: var curdate = new Date(); response.writeHead(200, { 'Set-Cookie':'sesh=wakadoo; expires='+curdate.toUTCString() }); 但唉,这似乎并没有工作。 铬只是忽略了我设置的过期,而Firefox从不加载页面。 我目前的目标是简单地给我的cookie一个可以被浏览器解释的过期date…有人知道如何做到这一点? 最好, 萨米