Actionscript 3 使用AdobeAIR获取外部IP
我们可以使用Java、C#或VB.NET获取外部IP。但我想用AdobeAIR来做。如何向该链接发出请求并获取其字符串?如下所示:Actionscript 3 使用AdobeAIR获取外部IP,actionscript-3,actionscript,network-programming,air,Actionscript 3,Actionscript,Network Programming,Air,我们可以使用Java、C#或VB.NET获取外部IP。但我想用AdobeAIR来做。如何向该链接发出请求并获取其字符串?如下所示: private function makeRequest():void { var loader:URLLoader = new URLLoader(); configureListeners(loader); var req:URLRequest=new URLRequest("http://www.whatismyip.com/auto
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);
}
下面是一种使用java或C#从whatismyip.com获取外部ip的方法,在这个问题中,由于它被破坏而被删除。不过,我会在答案中保留它。