HTTP Basic Authentication with HTTPService Objects in Adobe Flex/AIR

前端 未结 8 1441
梦谈多话
梦谈多话 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:09

    The setCredentials() & setRemoteCredentials() methods are intended for use with Flex/LiveCycle Data Services, so they probably don't apply in your case.

    This ought to work for you. I was able to reproduce this behavior on my server, and this fix seems to have done the trick; it still seems a bit odd this isn't more API-user-friendly, considering how common a use case you'd think it were, but nonetheless, I've tested and verified this works, given a valid SSL cert:

    private function authAndSend(service:HTTPService):void
    {
            var encoder:Base64Encoder = new Base64Encoder();
            encoder.encode("someusername:somepassword");
    
            service.headers = {Authorization:"Basic " + encoder.toString()};                            
            service.send();
    }
    

    Hope it helps! And thanks for posting -- I'm sure I would've run into this one sooner or later myself. ;)

提交回复
热议问题