Tag: http headers

在redirect之前设置快速响应标题

我正在实现一个站点login,接收电子邮件/密码组合,检索一个API令牌,并将其返回给用户以存储(encryption)localStorage。 目前,在成功发送到/login ,应用程序会将用户redirect到索引页面,并将该标记附加为查询,如下所示(如此处所示 ): login.post('/', function(req, res) { …checking password… Auth.getToken(user, function(err, token) { res.redirect('/?token=' + token); }); }); 这工作正常,但我宁愿保持我的URL尽可能干净,并设置标记为一个头,而不是: login.post('/', function(req, res) { …checking password… Auth.getToken(user, function(err, token) { res.set('x-access-token', token); console.log(res._headers); // –> {'x-powered-by': 'Express', 'x-access-token': <token>} res.redirect('/'); }); }); console.log -ing res._headers显示标题是按预期设置的,但是当我把请求中的req.headerslogging到索引页面时,它没有显示出来: { host: 'localhost:3000', connection: 'keep-alive', 'cache-control': 'max-age=0', accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'upgrade-insecure-requests': […]

Access-Control-Allow-Origin不允许来源http:// localhost。

我正在Node.JS中开发一个REST web服务来处理骨干框架。 我已经使用urlRoot定义了一个Person模型: http://localhost:3000/users并且我创build了一个请求处理程序,在接收到一个post请求时将这个人添加到数据库中。 app.post('/users', user.add(db)); exports.add = function(db){ return function(req,res){ console.log(req.body); var name = req.body.name; var age = req.body.age; var sex = req.body.sex; var job = req.body.job; var peopleDb = db.get('people'); peopleDb.insert({ 'name':name, 'age':age, 'sex':sex, 'job':job },function(e,docs){ if(e){ console.log(e); }else { res.setHeader('Content-Type','application/json'); res.setHeader('Access-Control-Allow-Origin','*'); res.setHeader('Access-Control-Allow-Methods','GET,PUT,POST,DELETE'); res.writeHead(200); res.end(JSON.stringify(docs)); } }); } } 当我尝试执行代码时,我在控制台中得到这个: Origin http://localhost is […]

如何在Azure函数中添加客户http标头

我尝试从客户端JavaScript应用程序谷歌身份validationazurefunction(nodejs)。 我已经为正确的URL设置了CORS(即http:// localhost:8080 )。 但是我仍然收到以下错误: 凭证标志是'true',但是'Access-Control-Allow-Credentials'标头是''。 允许凭证必须是“真实的”。 原因' http:// localhost:8080 '因此不被允许访问。 我已经在互联网上到处尝试,花了几天时间自己find答案。 看来,Azure http响应需要在标题中添加此Access-Control-Allow-Credentials:true。 有没有办法添加自定义标题? 任何帮助将不胜感激。

我应该使用什么编码来正确生成nodeJS中encryption的ETag?

在我的nodeJS应用程序中,我想为所有返回给客户端的内容生成ETags。 我需要ETag基于文件的实际内容而不是date,以便跨不同节点进程的同一文件具有相同的ETag。 现在我正在做以下工作: var fs = require('fs'), crypto = require('crypto'); fs.readFile(pathToFile, function(err, buf){ var eTag = crypto.createHash('md5').update(buf).digest('hex'); res.writeHead(200, {'ETag': '"' + eTag + '"','Content-Type':contentType}); res.end(buf); }); 我不知道我应该使用不同的encryption函数来编写适当的系统。 我应该使用非hex东西吗? 我应该得到fs.readFile调用返回一个hex编码的缓冲区? 如果是的话,会不会影响回报给用户的内容? 最好的和谢谢, 萨米

访问自定义请求标头节点expression

我正在build立一个快速的Web API,并没有find访问传入的自定义请求标题的信息。 例如,我期待一个传入的post请求有一个provider_identifier头。 当我收到请求时,我需要访问该头信息来validation其订阅。 有人能指出我在正确的方向/提供build议吗? router.post('myendpoint/', function(req, res){ var providerId = req.????; });

从express.js中删除所有标题

我正在创build一个页面,我有一些数据被其他设备parsing。 我曾经这样做与PHP,但我把它移动到节点。 我需要从页面中删除任何和所有标题,所以我只有我的输出。 这个输出是对GET请求的响应。 目前我有 HTTP/1.1 200 OK Date: Wed, 11 Sep 2013 11:54:14 GMT Connection: close My output 我需要它来显示 My output

如何在node.js中发送一个200响应

我有node.js 5.2.0,expression4.2.0和强大的1.0.17。 我创build了一个简单的表单来保存文本框和照片。 它工作正常,但问题是,在数据上传后,我可以看到在控制台,POST没有完成,它仍然待定。 为了完成它,我把这个添加到我的代码 form.on('end', function() { res.writeHead(200, {'Content-Type': 'text/plain'}); }); 我只想发送标题,并没有在页面上。 我希望系统得到200 ok回应,而不必在页面上打印任何东西。 但是POST还在等待。 如何解决这个问题,而不必打印任何东西? 什么样的标题我必须发送? 谢谢 UPDATE 如果我做 form.on('end', function() { res.end(); }); POST正常结束,但是我得到一个空白页。 这是为什么? 我只想上传一些东西,不打印页面上的任何东西,不redirect,留在同一页面。 再次感谢

节点js / Angular js – 小心:临时标题显示

这是我的Angular js代码: $http({ method:'POST', withCredential:true, url:$scope.config.app_ws+'auth/signup', data:{user:$scope.auth} }).success(function(status, response){ console.log(response); }).error(function(status, response){ alert(response+'Bummer 🙁 , an error occured plese retry later. '); }); 这是我的Node.js片后端: var allow_cross_domain= function(req, res, next) { res.header('X-Powered-By', 'hey.heyssssssss.org'); var oneof = false; if(req.headers.origin) { res.header('Access-Control-Allow-Origin', req.headers.origin); oneof = true; } if(req.headers['access-control-request-method']) { res.header('Access-Control-Allow-Methods', req.headers['access-control-request-method']); oneof = true; } if(req.headers['access-control-request-headers']) { res.header('Access-Control-Allow-Headers', […]

如何通过假设一个默认的内容typesparsingExpress / NodeJs中的缺less内容types的HTTP请求?

如果快速bodyParser不启动,我怎么能访问POST请求中的数据? var server = express(); server.use(express.bodyParser()); server.post('/api/v1', function(req, resp) { var body = req.body; //if request header does not contain 'Content-Type: application/json' //express bodyParser does not parse the body body is undefined var out = { 'echo': body }; resp.contentType('application/json'); resp.send(200, JSON.stringify(out)); }); 注意:在ExpressJs 3.x + req.body不是自动可用的,需要bodyParser来激活。 如果没有设置内容types标题,是否可以指定application/json的默认内容types并触发bodyParser ? 否则是否可以从这个快速POST函数内使用裸nodejs方式访问POST数据? (例如req.on('data', function… )

如何获取Node / Express中当前设置的HTTP响应头列表?

据我所知,当你在node / express或者其他东西中构build一个http响应时,这个过程主要由两个非连续的步骤组成:定义Headers和构造主体。 标题包括Set-Cookie标题。 在Express中,以下方法可用于设置标题的响应对象: res.append(); // To append/create headers res.cookie(); // A convenience method to append set-cookie headers. 由于头只是被缓冲,而不是实际发送,直到发送响应,是否有任何方法或机制,以获得当前列表头设置,连同它们的值,如: headers = res.getHeaders(); //Returns an object with headers and values headers = res.getHeaders('Set-Cookie'); // To get only select headers