2011-04-07 37 views
0

我們可以從外部IP獲得如何使用Java,C#或VB.NET從http://www.whatismyip.com/automation/n09230945.asp獲得我的外部IP。但我想用Adobe AIR來做到這一點。如何向該鏈接發送請求並獲取其字符串。請儘快幫助我。從http://www.whatismyip.com/automation/n09230945.asp使用Adobe AIR獲取外部IP

在此先感謝。

+0

這是一個獲取外部IP使用java或C#從whatismyip.com的方法http://stackoverflow.com/questions/5543738/difference-between-internal-ip-address-and-external-ip-address – 2011-04-07 20:25:40

回答

0

這將是這樣的:

private function makeRequest():void 
{ 
    var loader:URLLoader = new URLLoader(); 

    configureListeners(loader); 
    var req:URLRequest=new URLRequest("http://www.whatismyip.com/automation/n09230945.asp"); 

    try 

    { 
     var header:URLRequestHeader=new URLRequestHeader("content-type", "text/plain"); 

     var header2:URLRequestHeader = new URLRequestHeader("pragma", "no-cache"); 

     req.requestHeaders.push(header); 
     req.requestHeaders.push(header2); 

     req.method = URLRequestMethod.POST; 
     loader.dataFormat = URLLoaderDataFormat.TEXT; 
     loader.load(req); 
    } 
    catch (error:Error) 
    { 
     trace("Unable to load requested document."); 
    } 
} 

private function configureListeners(dispatcher:IEventDispatcher):void 
{ 
    dispatcher.addEventListener(Event.COMPLETE, completeHandler); 
} 

private function completeHandler(event:Event):void 
{ 
    var loader:URLLoader = URLLoader(event.target); 
    mx.controls.Alert.show("" + loader.data); 
} 

感謝所有。

+0

謝謝編輯:) – 2011-04-09 16:02:00