- Topics: Active | Unanswered
#1 2014-01-16 08:59:23
- develliot
Need example code in AS3 for API login using POST
I can successfully log in using GET with this code:
_____________________________________
///// _cookie is session ID obtained from common-info request
var loader:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest(_serverURL+LOGIN_URL+"&domain="+_domain+"&login="+userName+"&password="+password+"&session="+_cookie);
req.method = URLRequestMethod.GET;
req.contentType = "application/x-www-form-urlencoded";
loader.addEventListener(Event.COMPLETE, logInSuccess);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
loader.load(req);
____________________________________
However when I attempt to do this with POST it fails and returns:
<results>
<status code="no-data"/>
</results>
see code below:
_____________________________________________
var loader:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest(_serverURL+"/api/xml");
req.method = URLRequestMethod.POST;
/// have tried both "text/xml" and "application/xml"
req.contentType = "application/xml";
var dataXML:XML =
<params>
<param name="action">login</param>
<param name="login">{_userName}</param>
<param name="password">{_password}</param>
<param name="session">{_cookie}</param>
<param name="domain">{_domain}</param>
</params>
;
dataXML.normalize();
req.data = dataXML.toString();
loader.addEventListener(Event.COMPLETE, logInSuccess);
loader.addEventListener(IOErrorEvent.IO_ERROR, ioError);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
loader.load(req);
_____________________________________________________
When I do this in a browser using the "Advanced Rest Client" app in chrome it works fine and returns an "OK" but this doesn't seem to work from within my Pod code. I am guessing that the broswer app manages cookies automatically (may be) and my pod code using Flash Player doesn't do this. I Just don't know, may be there is an error in my AS3 code?
I don't want to log in with GET because if people aren't using HTTPS then all credentials are human readable in the request string which in my book is a big nono.
Does any one have any working example AS3 code with this work with a get?
Offline