Apache flex flex mobile项目:建立到特定url的http连接

Apache flex flex mobile项目:建立到特定url的http连接,apache-flex,http,Apache Flex,Http,如何在flex mobile项目中建立到特定url的http连接并从该url获取数据 谢谢功能: /* Function to make a generic HTTP Request * loc = location e.g. http://www.google.com * req = request * type = content type * complete = function to execute when HTTP req returns with complete *

如何在flex mobile项目中建立到特定url的http连接并从该url获取数据

谢谢

功能:

/* Function to make a generic HTTP Request
 * loc = location e.g. http://www.google.com
 * req = request 
 * type = content type
 * complete = function to execute when HTTP req returns with complete
 */
    public function httpReq(loc:String , req:String, type:String, complete:Function):void{
                /* Start the HTTP Request */
                try{
                    requestSender= new URLLoader();
                    requestSender.addEventListener(Event.COMPLETE, complete);
                    requestSender.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, printResponse);
                    var urlRequest :URLRequest = new URLRequest(loc);

                    /* Setup HTTP Request */
                    urlRequest.data = req;
                    urlRequest.contentType = type;
                    urlRequest.method = URLRequestMethod.GET;
                    requestSender.load(urlRequest); // Send the request off, when complete jump to completeHandler
                    }
                catch(e:Error){
                        trace(e.message);
                        trace(e.getStackTrace());
                    }
                }
获取响应:

/* HTTP Request complete, back with response */
private function responseHandler(event:Event):void
{
    this.requestSender = URLLoader(event.target); // Set requestSender as response
    this.output.text = this.requestSender.data; // Get its data
    trace("THE DATA IS "+this.requestSender.data);
    this.requestSender.close();
    alert.cancel();
}
示例调用:

httpReq("http://www.google.com" , "requestString", "application/x-www-form-urlencoded", responseHandler);
职能:

/* Function to make a generic HTTP Request
 * loc = location e.g. http://www.google.com
 * req = request 
 * type = content type
 * complete = function to execute when HTTP req returns with complete
 */
    public function httpReq(loc:String , req:String, type:String, complete:Function):void{
                /* Start the HTTP Request */
                try{
                    requestSender= new URLLoader();
                    requestSender.addEventListener(Event.COMPLETE, complete);
                    requestSender.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, printResponse);
                    var urlRequest :URLRequest = new URLRequest(loc);

                    /* Setup HTTP Request */
                    urlRequest.data = req;
                    urlRequest.contentType = type;
                    urlRequest.method = URLRequestMethod.GET;
                    requestSender.load(urlRequest); // Send the request off, when complete jump to completeHandler
                    }
                catch(e:Error){
                        trace(e.message);
                        trace(e.getStackTrace());
                    }
                }
获取响应:

/* HTTP Request complete, back with response */
private function responseHandler(event:Event):void
{
    this.requestSender = URLLoader(event.target); // Set requestSender as response
    this.output.text = this.requestSender.data; // Get its data
    trace("THE DATA IS "+this.requestSender.data);
    this.requestSender.close();
    alert.cancel();
}
示例调用:

httpReq("http://www.google.com" , "requestString", "application/x-www-form-urlencoded", responseHandler);

你试过做什么调查吗


你试过做什么研究吗