Flex Mobile Project: установить http-соединение с определенным URL - PullRequest
1 голос
/ 18 августа 2011

как установить http-соединение с определенным URL-адресом и получить данные из этого URL-адреса в проекте flex mobile.

Спасибо

Ответы [ 2 ]

1 голос
/ 18 августа 2011

Функция:

/* 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);
0 голосов
/ 18 августа 2011
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...