2011-11-18 4 views

답변

2

당신은 간단한 URLRequest 사용하여이 작업을 수행 할 수 있습니다

var loader:URLLoader = new URLLoader(); 
loader.dataFormat = URLLoaderDataFormat.TEXT; 
loader.addEventListener(Event.COMPLETE, loaderCompleteHandler); 
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); 
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); 

try 
{ 
    loader.load(new URLRequest("http://localhost:3000/api/user/id")); 
} 
catch (error:Error) 
{ 
    trace("Error loading URL: " + error.message); 
} 

function loaderCompleteHandler(e:Event):void 
{ 
    // and here's your response (in your case the JSON) 
    trace(e.target.data); 
} 

function httpStatusHandler(e:HTTPStatusEvent):void 
{ 
    trace("httpStatusHandler:" + e.status); 
} 

function securityErrorHandler(e:SecurityErrorEvent):void 
{ 
    trace("securityErrorHandler:" + e.text); 
} 

function ioErrorHandler(e:IOErrorEvent):void 
{ 
    trace("ioErrorHandler: " + e.text); 
} 
+0

을 아니 당신은 할 수 없습니다 없습니다 - 이것은 단지 GET 및 POST 요청을 수 있습니다,하지만 당신이 완료에 필요한 다른 HTTP 요청 방법에 대한 REST 서비스. – weltraumpirat

+2

사실, 질문자가 GET 응답을받을 수있는 방법을 요청했습니다. 그래서이 경우이 대답으로 충분합니다. –

+0

좋습니다. 충분하지 않으면 OP가 더 구체적이어야합니다. – weltraumpirat

관련 문제