AS3 AIR 3.5 for Android sending POST data in URLRe

2019-04-12 15:39发布

I'm trying to POST data to an external URL in my AIR for Android app to log in users. It works in the Flash Debugger on my pc, but does not work on my Android device. I have the Internet Permission set for my app. I have listeners set up for IO_ERROR and SECURITY_ERROR but neither of these are fired. It just hangs there and does nothing when I test on the device, but it works fine in the debug player!?!?

EDIT: I've already searched for answers and the closest I came was this: AS3 AIR URLLoader POST which suggest specifying a content-type in my request, but that doesn't solve my issue

EDIT: It also works when I upload it to server and add a crossdomain.xml to the requested site.

public static function login(user:String, pass:String):void 
    { 
        username = user;
        var request:URLRequest = new URLRequest( "http://mysite.com/"+user+"/login.json" ); 
        request.method = URLRequestMethod.POST; 
        request.contentType = 'application/x-www-form-urlencoded';

        var variables:URLVariables = new URLVariables(); 
        variables.p = pass;             
        request.data = variables; 

        var requestor:URLLoader = new URLLoader(); 
        requestor.addEventListener( Event.COMPLETE, loginRequestComplete ); 
        requestor.addEventListener( IOErrorEvent.IO_ERROR, httpRequestError ); 
        requestor.addEventListener( SecurityErrorEvent.SECURITY_ERROR, httpRequestError ); 
        requestor.load( request ); 
    } 

1条回答
Emotional °昔
2楼-- · 2019-04-12 16:02

Well, I finally managed to nail it....

I was grabbing my username and password from two textfields created in the ide.

The username textfield was set to multiline, which caused no problems in the online or debugger versions, but added a line break to the textfield on my android device, causing my api to return 400.

Changed it to a single line textfield and problem solved.

Crazy :)

查看更多
登录 后发表回答