Link to home
Start Free TrialLog in
Avatar of Joel_Sisko
Joel_SiskoFlag for United States of America

asked on

Using Flex to graphically display data from url request...

Dear Experts:

I am new to programming and as well as Flex/AIR from Adobe. I am trying to build an application that will send a url request to a server and then take the information returned from the request and display that information visually.

The server we are using requires first for us to login, the url to do that is:

http://192.168.170.128:7878/command=Login&username=admin&secret=1234

The response to that request is as such:

<ajax-response>
<response type="object" id="unknown">
<generic response="Success" message="Authentication accepted"/>
</response>
</ajax-response>

Then I want to execute the command that will return the system users, the url for that is:

http://192.168.170.128:7878/command=listusers

The response to that is as such:

<ajax-response>
<response type="object" id="unknown">
<generic response="Success" message="User list will follow"/>
</response>
<response type="object" id="unknown">
<generic event="userEntry" Usertype="Private" Username="John" Location="NJ" status="Active"/>
</response>
<response type="object" id="unknown">
<generic event="userEntry" Usertype="Private" Username="Tim" Location="CA" status="Active"/>
</response>
<response type="object" id="unknown">
<generic event="userEntry" Usertype="Public" Username="Bob" Location="VA" status="Active"/>
</response>
<generic event="UserlistComplete"  TotalUsers="3"/>
</response>
</ajax-response>

So I would like to do is this:

Have a basic AIR application that has a button that when pressed will login in the user and will return the user information showing an image for each user based on user type (Public or Private), then provide a label under that image that shows the username and location.

I hope this is enough information in advance.

Thanks,

Joel
Avatar of evcr
evcr
Flag of United Kingdom of Great Britain and Northern Ireland image

Not tested but should be close..
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
private	var loginVars:URLVariables = new URLVariables();
 
private function goLogin():void {
	loginVars.command = 'Login';
	loginVars.username = username.text;
	loginVars.secret = secret.text;
	doLogin.send(loginVars);
}
 
private function httpResult(e:event):void {
	if (httpSvc.lastResult.response[0].generic.@message == 'Authentication accepted') {
		loginVars.command = 'listusers';
		doLogin.send(loginVars);		
	}
	if (httpSvc.lastResult.response[0].generic.@message == 'User list will follow') {
		trace (httpSvc.lastResult.response[1].generic.@event);
		trace (httpSvc.lastResult.response[1].generic.@Usertype);
		trace (httpSvc.lastResult.response[2].generic.@event);
		trace (httpSvc.lastResult.response[2].generic.@Usertype);
		//etc.... 
		//should get you started
	}
}
]]>
</mx:Script>
<mx:HTTPService result="httpResult(event);" resultFormat="e4x" id="httpSvc" url="http://192.168.170.128:7878/" useProxy="false" method="POST"/>
	<mx:Button x="149" y="154" label="login" click="goLogin();"/>
	<mx:TextInput id="username" x="99" y="86" text="admin"/>
	<mx:TextInput id="secret" x="99" y="116" text="1234"/>
</mx:Application>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of evcr
evcr
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Joel_Sisko

ASKER

evcr,

Thanks for the response. It was not working at first, so I used wireshark to capture the login from a regualr browser that works. I noticed that user FireFox is was using GET verses POST, so I changed that and now I can see on the server the request to autneticate.

The information being sent should be:

action=Login&username=admin&secret=1234

But I am getting this:

action=Login&secret=1234&username=admin

I tried switching the lines in the "goLogin()" hoping the order would rectify, but still the same result.

Joel
is this on a https service?

if so you should be using  'https..' etc. in the url.

Also you may need a crossdomain.xml file to allow the ip ports to converse.

e.g. try this crossdomain.xml file:
<?xml version="1.0" encoding="iso-8859-1"?>
<cross-domain-policy>
<allow-access-from domain="*" ports="80,443" secure="false" />
</cross-domain-policy>

If it works then adjust your secruity in this file respectively;
evcr,

No this is on http, but I found the problem just not the solution:

        httpVars.action = 'Login';
        httpVars.usernam = 'admin;
        httpVars.secret = '1234';
        httpSvc.send(httpVars);

When the request is sent, it is putting the variables in alphabetical order, command+secret+username, where I need the order to be command+username+secret.

I confirmed this by using Zsecret instead of secret and the order was right just Zsecret will not do anything.

Joel
evcr,

I have the same result using <mx:request>, that is the values are being alphabetically sorted.

Joel
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 
<mx:Script>
<![CDATA[
 
private function goLogin():void {
	
        httpSvc.send();
}
 
]]>
</mx:Script>
 
<mx:HTTPService resultFormat="e4x"  id="httpSvc" url="http://192.168.170.128:8088/server/commands" showBusyCursor="true" useProxy="false" method="GET">
      <mx:request xmlns="">
            <zcommand>Login</zcommand>
            <ausername>admin</ausername>
            <password>1234</password>
      </mx:request>
</mx:HTTPService>
 
<mx:Button x="99" y="155" label="login" click="goLogin();"/>
 
</mx:WindowedApplication>

Open in new window


Yes I noticed that, normally it would not matter what order they were in but I guess the web service in your case isn't that sort of beast. Having said that I think it unnecessary that Flex is ordering them.

As I don't have access to your web service it's difficult to test. Could you try constructing a URLRequest from the variables and see if that works.

See code below...





//untested!
private function goLogin():void {
var requestString:String = 'http://192.168.170.128:7878/command=Login&username='+username.text+'&secret='+secret.text;
var request:URLRequest = new URLRequest(requestString);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, httpResult);
loader.load(request);
}
 
private function httpResult(event:Event):void {
	var httpSvc:XML = XML(event.target.data);
	trace(httpSvc.toXMLString());
//If the trace is good here you can use my previous code to query the xml data
}

Open in new window

evcr,

Bonehead move on my part, kept looking at captured packets verses if the connection actually worked with the server. Doh! It does in any order.

Thanks for sticking with me thorough this and all the help.

If you ever have a question on VoIP or phone systems in general follow my profile or head over to the VoIP section of EE.

Joel
No prob. Cheers!