Node.js - 带cookie的多个请求(Node.js - multiple requests with cookies)
我正在使用Node.js构建一个应用程序。 我正在使用
request
包来发出服务器端GET请求。 具体来说,我正在发出使用自定义HTTP标头的请求:https://www.npmjs.com/package/request#custom-http-headers
该文档显示了如何一次发出一个请求。 但是,我需要向两个不同的API发出请求。 有谁知道如何做到这一点? 我目前提出一个请求的代码:
var cookie = parseCookie.parseCookie(req.headers.cookie); var cookieText = 'sid='+cookie; var context; function callback(error, response, body) { var users = JSON.parse(body); res.render('../views/users', { context: users }); } var options = { url: 'http://localhost:3000/api/admin/users/', headers: { host: 'localhost:3000', connection: 'close', cookie: cookieText } }; request(options, callback); //need to make a request to another API.
作为旁注,我需要使用自定义HTTP标头的原因是我可以包含一个cookie,以便我的API可以进行身份验证。
I am building an app using Node.js. I am using the
request
package to make server-side GET requests. Specifically, I am making requests that use custom HTTP headers:https://www.npmjs.com/package/request#custom-http-headers
The documentation shows how to make one request at a time. However, I need to make a request to two different API's. Does anyone have any idea how to do this? My current code for making one request:
var cookie = parseCookie.parseCookie(req.headers.cookie); var cookieText = 'sid='+cookie; var context; function callback(error, response, body) { var users = JSON.parse(body); res.render('../views/users', { context: users }); } var options = { url: 'http://localhost:3000/api/admin/users/', headers: { host: 'localhost:3000', connection: 'close', cookie: cookieText } }; request(options, callback); //need to make a request to another API.
As a side note, the reason I need to use custom HTTP headers is so I can include a cookie so my API can authenticate.
原文:https://stackoverflow.com/questions/34958018
最满意答案
Eric的另一个答案是错误的。 他提到的命名空间声明与这个问题无关。
它不起作用的真正原因是由于安全问题 (参见第4197 号 问题 , 第111905号 )。
想象这种情况:
您收到一封来自攻击者的电子邮件,其中包含您下载的附件的网页。
您可以在浏览器中打开现在的本地网页。
本地网页创建一个
<iframe>
其源代码为https://mail.google.com/mail/ 。由于您已登录Gmail,该框架会将邮件加载到收件箱中。
本地网页通过使用JavaScript来访问
frames[0].document.documentElement.innerHTML
来读取帧的内容。 (在线网页将无法执行此步骤,因为它来自非Gmail来源;同源策略会导致读取失败。)本地网页将您的收件箱的内容放入
<textarea>
并通过表单POST将数据提交给攻击者的Web服务器。 现在攻击者有你的收件箱 ,这可能对垃圾邮件或识别盗窃是有用的。通过对使用Chrome打开的本地文件进行限制, Chrome可以覆盖上述情况。 为了克服这些限制,我们有两个解决方案:
尝试使用
--allow-file-access-from-files
标志运行Chrome。 我没有自己测试,但如果它有效,您的系统现在也将容易受到上述类型的场景的影响。将其上传到主机,问题解决。
At the time of writing, there was a bug in chrome which required an
xmlns
attribute in order to trigger rendering:<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" ... >
This was the problem I was running into when serving the xml file from a server.
If unlike me, you are viewing the xml file from a
file:///
url, then the solutions mentioning--allow-file-access-from-files
are the ones you want
相关问答
更多-
如果要访问参数,则需要使用$前缀。 也就是说,do contains($Type,'NEW')而不contains(Type,'NEW') 。 后者正在寻找一个名为Type的子元素,而不是传入的参数 试试这个模板。 请注意,您实际上不需要使用带有concat xsl:value-of来输出文本。Eric的另一个答案是错误的。 他提到的命名空间声明与这个问题无关。 它不起作用的真正原因是由于安全问题 (参见第4197 号 问题 , 第111905号 )。 想象这种情况: 您收到一封来自攻击者的电子邮件,其中包含您下载的附件的网页。 您可以在浏览器中打开现在的本地网页。 本地网页创建一个遗憾的是,没有一个浏览器本身支持XSLT 2.0。 我认为他们都在等待其他人先行动。 Sadly, none of the browsers yet support XSLT 2.0 natively. I think they're all waiting for the others to move first.我再次考虑了这个问题,然后推测,如果您只是简单地创建一个虚拟的XML DOM文档,然后从HTML DOM文档importNode元素,那么您是否需要为Chrome或Webkit定制克隆或序列化。 所以我写了http://jsfiddle.net/5TNH9/ ,事实上Chrome 13和Safari 5.1至少都会进行转换。 所以这可能是避免用自己的脚本代码完全实现序列化或克隆的另一种选择。 但是请注意,在jsfiddle的测试案例中,Chrome和Safari都会出现重复的br元素的问题,这些问题在Moz ...
xslt形式不适用于当前的Firefox,但与Chrome完美配合(xslt forms not working with current Firefox but works perfect with Chrome)[2019-12-04]
看起来你有两个嵌套的form元素,因为大多数浏览器都会将转换结果提供给你可能会使用它的HTML解析器。 但是,Mozilla会呈现XSLT转换的结果树,这意味着HTML解析器无法进行更正。 这可以解释这种差异。 It seems you have two nested form elements, as most browsers feed the transformation result to the HTML parser you might get away with that. Mozilla, ...您没有向我们展示您的XSLT,但通常可以使用normalize-space()将XSLT剥离出空格: You haven't shown us your XSLT, but often you can have XSLT strip out whitespace by using normalize-space():在Chrome扩展程序中对chrome:// url的href如何使其工作(a href to chrome:// url in a chrome extension how to make it work)[2022-10-17]
您无法从扩展程序访问Chrome页面。 但是,您可以使用Chrome API获取一些设置 特别是书签API , 已安装的扩展API You cannot access chrome pages from an extension. However you could get some settings with Chrome APIs Specifically Bookmarks API, Installed extensions API在浏览器中测试XSLT的一种非常简单的方法是将以下标头添加到XML源文档中: 然后在浏览器中加载它(XML源代码)。 另一种选择是使用带有一些javascript的独立HTML文档来加载XML和XSLT文档并启动转换。 这些都不能真正取代专用应用程序。 另请注意,您已使用XSLT 2.0对此进行了标记,但我不知道任何支持它的浏览器。 A super-simple way to test y ...Javeline XSLT示例(Javeline XSLT example)[2023-11-26]
请注意,Sarrisa是一个薄层,可以为XML处理创建单个API。 水下它仍然使用浏览器XML API,因此仍然可以暴露浏览器特定的怪癖。 由于Webkit现在提供XSLT支持,但是链接问题中显示了一些怪癖,这也有点过时了。 Javeline XSLT Compatability脚本虽然是一个非常好的扩展,但也有它的缺点。 一个主要问题是不支持完整的xpath 1.0频谱。 您可以像使用XSLTProcessor一样使用它, 请参阅此处,确保使用正确的包含序列,如此处所示 。 Please be aware ...我希望它能解决你的问题 function transform($xmlvalue, $xsl,$paraArray=array(),$IsFileXML=FALSE) { $XML = new DOMDocument(); if ($IsFileXML) $XML->load( $xmlvalue); else $XML->loadXML( $xmlvalu ...相关文章
更多- Node.js视频教程
- 《MLDN出品 魔乐科技Node.JS + MongoDB(JSP、HTML 、XML、JavaScript、Servlet、Struts、Ajax)视频汇总》(Node.JS + MongoDB\JSP、HTML 、XML、JavaScript、Servlet、Struts、Ajax nodejs)V2013[压缩包]
- Hadoop Backup Node
- Hadoop node 部署步骤
- 社区版Federated HDFS(多Name Node)实现浅析
- 如何加载JS,JS应该放在什么位置?-高性能web开发
- 开源项目列表
- 微信会员注册开发【带源码】:网页授权,得到code后在当前页面获取openid,js+php实现跨域请求
- Hadoop 解除 “Name node is in safe mode”
- Hadoop 解除 “Name node is in safe mode”
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。