如何在使用 Flex RemoteObject 方法时设置 HTTP 标头?
我在服务器端运行 blazes。 我想使用 http 标头过滤 http 请求。 我的目标是在不更改我的 blazeds 服务签名的情况下向服务器发送额外的参数。
在客户端,我使用 Flex RemoteObject 方法。
对于 Flex WebService 组件,可以使用属性 httpHeaders 设置 http 标头。 我在 RemoteObject 类上没有找到类似的东西......
I am running blazeds on the server side. I would like to filter http requests using an http header. My goal is to send extra parameters to the server without changing the signatures of my blazeds services.
On the client side, I am using Flex RemoteObject methods.
With Flex WebService components, it is possible to set an http header using the property httpHeaders. I have not found anything similar on the RemoteObject class...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可能正在尝试重新发明轮子。 是否有原因导致您无法使用标准 HTTP(s) 身份验证?
You might be trying to re-invent the wheel. Is there a reason you can't use the standard HTTP(s) authentication?
我也考虑使用 http 标头的一个原因是服务器能够在服务版本控制的上下文中“识别”flex 客户端。
在服务器上,我始终可以构建一个间接/代理,允许不同的客户端仅使用 1 个端点并根据客户端版本路由到正确的适配器。
问题出在客户端。 服务器如何识别 Flex 客户端令牌或“版本”。 一种方法当然是通过身份验证。 但是,假设不涉及身份验证呢?
A reason I was thinking too to use http headers was for the server to be able to 'recognize' the flex client in the a context of service versionning.
On the server I can always build an indirection/proxy that would allow the different clients to only use 1 end point and route to the right adapter depending on the client version.
The question is on the client side. How would the server identify the flex client token or 'version'. One way is certainly via authentication. But, assuming there is not authentication involved?
您可以在 PHP 中调试 $GLOBALS 来查看这一点。
我认为这是在
或者你可以简单地做
You can debug the $GLOBALS in PHP to see that.
I think this is in the
or you can simple do
我们最近遇到了同样的问题,这就是我们在不创建子类的情况下添加自定义标头的方式:
实际上可以通过 mx_internal 命名空间通过操作对象访问 AsyncRequest 对象。
We recently run into the same issue and this is how we added our custom headers without creating a subclass:
The AsyncRequest object is actually accessible via the operation object via the mx_internal namespace.
这对我使用 BlazeDS 和 Spring-Flex 1.5.2
Flex:
Java Spring-Flex:
dispatcher-servlet.xml 有效
This worked for me using BlazeDS and Spring-Flex 1.5.2
Flex:
Java Spring-Flex:
dispatcher-servlet.xml
我无法修改来自 Flex 的 http 请求,而是可以将自定义标头添加到
RemoteObject
发送到服务器的mx.messaging.messages.IMessage
中,并扩展flex.messaging.services.remoting.adapters.JavaAdapter
(用于访问Spring bean),可以读取标头参数并将它们放入HTTPRequest中。在弹性部分,我必须扩展 mx.rpc.AsyncRequest :
声明一个新属性“header”并覆盖调用方法,该方法检查是否存在用于设置 msg.headers 的非空值。
和 mx.rpc.remoting.mxml.RemoteObject:
构造函数创建自定义 AsyncRequest 的新实例并覆盖旧的 AsyncRequest,并定义一个将参数设置为自定义 AsyncRequest 的
setHeaders
方法。com.asfusion.mate.actions.builders.RemoteObjectInvoker(额外:P):
该函数读取 Mate 映射
RemoteObjectInvoker
中声明的参数,并将其放入RemoteObject
标头中。我希望它是可以理解的(用我的 apache english xDDD)
再见。 亚古珥!
I couldnt modify http request from flex, instead I can add custom headers to the
mx.messaging.messages.IMessage
thatRemoteObject
sends to the server and there, extendingflex.messaging.services.remoting.adapters.JavaAdapter
(used for accessing Spring beans), it's posible to read the header parameters and put them into the HTTPRequest.In the flex part, I had to extend
mx.rpc.AsyncRequest
:declares a new property "header" and overwrites invoke method that checks if there is a not null value for set the msg.headers.
and
mx.rpc.remoting.mxml.RemoteObject
:the constructor creates a new instance of our custom AsyncRequest and overwrite old
AsyncRequest
and it defines asetHeaders
method that set the argument to the customAsyncRequest
.com.asfusion.mate.actions.builders.RemoteObjectInvoker
(extra :P):this one reads the param declared in the Mate's map
RemoteObjectInvoker
and puts in theRemoteObject
header.I hope it will be understandable (with my apache english xDDD)
Bye. Agur!
RemoteObject 使用 AMF 作为数据通道,其管理方式与 HttpService 或 WebService(使用 Http)完全不同。
您可以做的是调用
setCredentials(username,password)
,然后使用 FlexLoginCommand(容器的标准命令,或派生您自己的命令)在服务器端捕获此信息。查找
setCredentials
以及如何在双方(客户端和服务器)处理此问题。RemoteObject uses AMF as the data channel, and is managed in a completely different way than HttpService or WebService (which use Http).
What you can do, is call
setCredentials(username,password)
and then capture this on the server side using the FlexLoginCommand (either the standard one for your container, or derive your own).Lookup
setCredentials
and how you should handle this on both sides (client and server).我有类似的问题,恐怕在使用 AMF 时没有简单的方法来设置 HTTP 标头。 但我设计了以下解决方案。
Flex使用HTTP传输AMF,但通过浏览器接口调用它,这允许您设置cookie。 就在包含应用程序调用的文档中,以下 JavaScript
浏览器应将其传输到服务器,并且您可以进行过滤(如果用户关闭 cookie,则会出现问题)。
您还可以从 Flex 调用更多 JavaScript 函数(更多信息请参见:http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html)。
I have similar problem, and I afraid there is no simple way to set HTTP header when using AMF. But I've designed following solution.
Flex uses HTTP to transfer AMF, but invokes it through browser interfaces, this allows you to set cookie. Just in document containing application invoke following JavaScript
Browser should transfer it to server, and you can filter (problem will be if the user will have cookies turned off).
Much more you can invoke JavaScript functions from Flex (more is here: http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html).