Flex mobile HTTPMultiService set user-agent

302 Views Asked by At

I'm developing a Flex mobile application and I'm using the Http Services within FlashBuilder (4.7) to send/receive data. I'm having some issues with how the server is setup to accept calls (from the mobile platform) and apparently setting the User-Agent in Android works just fine. But I can't seem to be able to find a way to set the User-Agent in FlashBuilder.

Any ideas?
Thanks

2

There are 2 best solutions below

0
JK Patel On
var request:URLRequest=new URLRequest('URL_OF_YOUR_SERVICE');
            var userCredential:Object = new Object();
            userCredential['user_email'] = 'YOUR_MAIL';
            userCredential['user_password'] = 'YOUR_PASSWORD';

            request.data=JSON.stringify(userCredential);// use this if your service accept json only else give Object directly
            request.method = 'post';// specify here method GET or POST
            var loader:URLLoader=new URLLoader();
            loader.addEventListener(Event.COMPLETE, userLoginCompleteHandler);
            loader.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHanlder);
            try
            {
                loader.load(request);
            }
            catch(error:Error)
            {
                trace("Login Error:: "+ error.toString());
            }

may this will help you, here i have defined userLoginCompleteHandler and onIOErrorHanlder event listner for result and fault.

0
Brian On

No, you can't set the User-Agent header in Flex.

From this Adobe forums post:

Note again that since the underlying Flash API is flash.net.URLLoader there are certain headers that you cannot send. For details, please see the docs for flash.net.URLRequestHeader.

The URLRequestHeader docs say:

In Flash Player and in Adobe AIR content outside of the application security sandbox, the following request headers cannot be used:

... User-Agent, ...