HTTP Basic Authentication with HTTPService Objects in Adobe Flex/AIR

前端 未结 8 1426
梦谈多话
梦谈多话 2020-12-04 14:52

I\'m trying to request a HTTP resource that requires basic authorization headers from within an Adobe AIR application. I\'ve tried manually adding the headers to the request

8条回答
  •  一整个雨季
    2020-12-04 15:04

    This is how its done.

    import mx.utils.Base64Encoder;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.http.HTTPService;
    
    var _oHttp:HTTPService = new HTTPService;
    var sUsername:String = "theusername"
    var sPassword:String = "thepassword";
    
    var oEncoder:Base64Encoder = new Base64Encoder(); 
    oEncoder.insertNewLines = false; 
    oEncoder.encode(sUsername + ":" + sPassword); 
    
    _oHttp.method = "POST";
    _oHttp.headers = {Authorization:"Basic " + oEncoder.toString()}; 
    

提交回复
热议问题