2011-04-07 38 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