代码之家  ›  专栏  ›  技术社区  ›  Alexandre Victoor

如何在使用flex remoteobject方法时设置http头?

  •  4
  • Alexandre Victoor  · 技术社区  · 16 年前

    我在服务器端运行blazeds。我想使用http头过滤http请求。我的目标是在不改变我的BLZEDS服务的签名的情况下向服务器发送额外的参数。

    在客户端,我使用flex 远程对象 方法。

    使用flex webservice组件,可以使用属性设置http头 httpheaders文件 是的。我在remoteobject类中没有找到类似的内容…

    8 回复  |  直到 16 年前
        1
  •  3
  •   hongo    15 年前

    我不能修改来自flex的http请求,而是可以将自定义头添加到 mx.messaging.messages.IMessage 那个 RemoteObject 发送到服务器并在那里扩展 flex.messaging.services.remoting.adapters.JavaAdapter (用于访问springbean),可以读取头参数并将其放入httprequest。

    在弯曲部分,我不得不延长 mx.rpc.AsyncRequest 以下内容: 声明一个新的属性“头”,并重写调用方法,检查是否有一个非空值来设置MSG标题。

    mx.rpc.remoting.mxml.RemoteObject 以下内容: 构造函数创建自定义异步请求的新实例并覆盖旧实例 AsyncRequest 它定义了 setHeaders 方法,该方法将参数设置为自定义 异步请求 是的。

    com.asfusion.mate.actions.builders.RemoteObjectInvoker (额外:P): 这一个读取在配偶地图中声明的参数。 RemoteObjectInvoker 远程对象 头球。

    我希望这是可以理解的(用我的apache英语xdd)

    再见。阿格尔!

        2
  •  3
  •   Ronny Shibley    10 年前

    这对我使用blazeds和spring flex 1.5.2很有效

    弯曲:

    use namespace mx_internal;
    
    var service:RemoteObject = new RemoteObject(destination);
    var operation:Operation = service[functionName];
    operation.asyncRequest.defaultHeaders  = {company:'company'};
    
    var token:AsyncToken =  operation.send();
    

    Java Spring Flex:

    public class FlexJavaCustomAdapter extends JavaAdapter{
        @Override
        public Object invoke(Message message) {
            String locale = (String) message.getHeader("com.foo.locale");   
            return super.invoke(message);
        }   
    }
    

    Dispatcher-Servlet.xml调度程序

    <bean id="customAdapter" class="org.springframework.flex.core.ManageableComponentFactoryBean">
                <constructor-arg value="com.codefish.model.flex.FlexJavaCustomAdapter"/>
            </bean> 
    
            <flex:message-broker id="_messageBroker"  services-config-path="classpath*:/com/codefish/resources/spring/services-config.xml"  > 
                  <flex:remoting-service default-adapter-id="customAdapter" 
                default-channels="my-amf, my-secure-amf" />
            </flex:message-broker>
    </bean>
    
        3
  •  1
  •   Verdant    16 年前

    ReloTeObjor使用AMF作为数据通道,并以与HTTPService或WebService(使用HTTP)完全不同的方式进行管理。 你能做的,就是打电话 setCredentials(username,password) 然后使用flexlogincommand(容器的标准命令或派生自己的命令)在服务器端捕获它。 查找 setCredentials 以及如何在双方(客户机和服务器)处理此问题。

        4
  •  1
  •   sth    14 年前

    我也有类似的问题,恐怕在使用amf时没有简单的方法来设置http头。但我设计了以下解决方案。

    flex使用http传输amf,但通过浏览器接口调用它,这允许您设置cookie。在包含JavaScript的应用程序调用的文档中

    document.cookie="clientVersion=1.0;expires=2100-01-01;path=/";
    

    浏览器应将其传输到服务器,您可以进行筛选(问题是用户是否将关闭cookies)。

    您还可以从flex调用更多javascript函数(更多内容如下: http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_4.html )中。

        5
  •  0
  •   David    16 年前

    你可能想重新发明轮子。您不能使用标准http(s)身份验证的原因是什么?

        6
  •  0
  •   elextra    16 年前

    我想使用http头的一个原因是服务器能够在服务版本化的上下文中“识别”flex客户机。 在服务器上,我总是可以建立一个间接/代理,允许不同的客户端根据客户端版本只使用1个端点和路由到正确的适配器。 问题在客户方面。服务器如何识别flex客户端令牌或“版本”。一种方法当然是通过身份验证。但是,假设不涉及身份验证?

        7
  •  0
  •   yiotix    10 年前

    我们最近遇到了同样的问题,这就是我们在不创建子类的情况下添加了自定义标题的方法:

    var operation:AbstractOperation = _remoteSession.getOperation('myRemoteOperation');
    var async:AsyncRequest = operation.mx_internal::asyncRequest;
    async.defaultHeaders = {my_header:'my_value'};
    

    asyncrequest对象实际上可以通过操作对象通过mx_内部命名空间访问。

        8
  •  -1
  •   Marcelo Rodovalho    12 年前

    您可以调试php中的$globals来查看它。 我想这是在

    $GLOBALS['HTTP_RAW_POST_DATA'];
    

    或者你可以简单的做

    file_get_contents('php://input');
    
    推荐文章