在Flex中,我可以发送HTTPService POST请求而不是GET请求吗?

在Flex中,我可以发送HTTPService POST请求而不是GET请求吗?

问题描述:

当Flex(HTTPService)正在加载XMLSSL时,在Internet Explorer (6,7)中存在已知问题。在这种情况下,Flash Player掷出Error #2032: Stream Error在Flex中,我可以发送HTTPService POST请求而不是GET请求吗?

根据Microsoftothers的建议,应该在服务器端设置“Cache-Control:no-store”来解决问题。

不幸的是,我没有访问应用程序的后端,因此我应该通过Flex解​​决它。

我的目标是在运行时加载带有配置的xml文件。
在Flex中不允许使用GET请求的自定义标头(如果我错了,请告诉我)。因此我决定用POST请求完成我的目标,而且令人惊讶的是它工作得很好。

这里是我带着代码:

var httpService:HTTPService = new HTTPService(); 
httpService.url = 'config.xml'; 
httpService.method = 'POST'; 
httpService.requestTimeout = 10; 
httpService.contentType = "application/xml"; 
httpService.headers["Cache-Control"] = "no-store"; 
httpService.resultFormat = "e4x"; 
var localResponder:Responder = new Responder(
    function(event:ResultEvent):void { 
     //event.result returns the required xml configuration 
    }, 
    function(event:FaultEvent):void { 
    }); 
var token:AsyncToken = httpService.send({}); 
token.addResponder(localResponder); 

我的问题是:难道还有任何副作用,当被发送,而不是GET请求POST要求?



UPDATE:

为了证明GET-请求被剥去头,我已经采取了由@ Reboog711提供的代码并创建了一个小程序。这里是代码:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx"> 

    <fx:Script> 
     <![CDATA[ 
      import mx.rpc.http.HTTPService; 

      protected function sendHTTPRequest(event:MouseEvent):void 
      { 
       var httpService:HTTPService = new HTTPService(); 
       httpService.url = 'xml.xml'; 
       var headerData : Object = new Object(); 
       headerData['Cache-Control'] = 'no-store'; 
       httpService.headers = headerData; 
       httpService.send(); 
      } 
     ]]> 
    </fx:Script> 

    <s:Button label="SEND HTTP REQUEST" 
       horizontalCenter="0" verticalCenter="0" click="sendHTTPRequest(event)"/> 

</s:Application> 

这里是我在查尔斯应用程序中看到,当我发送HTTP请求。

enter image description here

您可以自己右here测试。而且,当我试图解决我的问题时,我看到很多证据表明GET请求不能用自定义标题发送。你可以看看here

谢谢!

+2

如果它能正常工作,并且您在浏览器控制台中看不到任何错误,并且您的Web服务器日志中没有错误(这可能看不到),但我不担心它。我不知道你不能在Flex中使用带有GET的自定义标题,你试过了吗?基本上,POST/GET之间的区别在于“消息正文”或数据被发现的位置,在这种情况下,您实际上并未发布任何数据。 GET/POST意味着什么(可能会影响缓存等)有一些语义上的差异,但我不认为你在做什么会有任何实际的伤害。 –

您应该可以在没有任何问题的情况下将headers添加到HTTPService请求中。在将Flex应用程序与YouTube API集成之前,我已经完成了它。从概念上讲,它应该是这样的:

var httpService:HTTPService = new HTTPService(); 
var headerData : Object = new Object(); 
headerData['Cache-Control'] = 'no-store'; 
http.headers = headerData; 

如果您执行Google Search其他链接出现。只要您的服务支持GET和POST请求;我不知道你为什么会遇到任何问题。

+0

谢谢@Reboog711!我已经把你的代码和创建了一个应用程序来测试你的陈述(请看问题的更新)。我想证明是错误的,但我确信自定义标头只能使用'POST'请求​​。 –