這將是這樣的:
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);
}
感謝所有。
這是一個獲取外部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