发出 HTTPRequest 并获得响应 (Adobe Flex) [英] Making HTTPRequest and getting response (Adobe Flex)
问题描述
我尝试在 Adobe Flex (Actionscript) 中发出 HTTP 请求,如下所示:
Im trying to make a HTTP Request in Adobe Flex (Actionscript) as follows:
var p:PersonSearchController = new PersonSearchController();
showAlertDialog();
p.search(sc);
alert.cancel();
navigator.pushView(views.PersonSearchResults, +p.getResp());
所以基本上,在搜索之前我们会得到一个正在搜索..."警报对话框,一旦搜索完成,对话框就会消失,结果屏幕会被推到屏幕上...
So basically, before the search we get a "Searching..." AlertDialog box, once the search is complete, the dialog box disappears and the results screen is pushed onto the screen...
这里是搜索方法:
function search{
var requestSender:URLLoader= new URLLoader();
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
var urlRequest :URLRequest = new URLRequest("http://airpoint05:8888/MPS2/PersonSearch");
var msg:String = "blah";
/* Setup HTTP Request */
urlRequest.data = msg;
urlRequest.contentType = "application/x-www-form-urlencoded";
urlRequest.method = URLRequestMethod.POST;
requestSender.load(urlRequest);
}
这里是 completeHandler 函数:
And here is the completeHandler function:
/* URL has completed and got a response */
private function completeHandler(event:Event):void
{
var response:URLLoader = URLLoader(event.target);
this.res = URLLoader(event.target).data;
trace(this.res);
response.close();
}
当这一行被调用时:navigator.pushView(views.PersonSearchResults, +p.getResp());
When this line is called: navigator.pushView(views.PersonSearchResults, +p.getResp());
p.getResp() 什么都不是,因为响应还没有回来.我希望程序基本上阻塞,直到收到 HTTPResponse 以便我可以处理结果.目前,弹出窗口快速出现和消失,并且在后台搜索停止并发出请求......我得到了响应,但只有在结果屏幕被推出后.在我们有 HTTP 响应之前,如何阻止弹出窗口?
p.getResp() is nothing as the response hasn't came back yet. I want the program to basically block until the HTTPResponse is received so I can process the results. At the moment the Popup appear and disappears quickly, and in the background the search goes off and makes the request... I get the response but only after the results screen has been pushed out. How can I make the popup block until we have a HTTPresponse?
谢谢菲尔
推荐答案
不要为此使用 URLLoader,使用 HTTPService:
Don't use URLLoader for this, use HTTPService:
<fx:Script>
<![CDATA[
private function search(text:String):void
{
service.send({search:text}); // your service will receive the variable 'search' with your string
}
private function resultHandler(e:ResultEvent):void
{
var data:Object = e.result;
// do whatever else here
}
]]>
</fx:Script>
<s:HTTPService id="service" method="POST" url="http://airpoint05:8888/MPS2/PersonSearch" result="resultHandler" />
这篇关于发出 HTTPRequest 并获得响应 (Adobe Flex)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!