I am trying to request an HTTP resource for which the original authorization headers are required from within the Adobe Air app I have tried manually adding the header to request, as well as to use the setRemoteCredentials () method, they have no use.
Here is the code:
& lt; Mx: script & gt; & Lt ;! [CDATA [import mx.rpc.events.ResultEvent; Import mx.rpc.events.FaultEvent; Private function authAndSend (service: HTTPService): zero {service.setRemoteCredentials ('someusername', 'somepassword'); Service.send (); } Private Function Results Handler (Event: ResultEvent): Zero {apiResult.text = event.result.toString (); } Private function result (event: FaultEvent): zero {apiResult.text = event.fault.toString (); }] & Gt; & Lt; / Mx: script & gt; & Lt; Mx: HTTPService id = "apiService" url = "https://mywebservice.com/someFileThatRequiresBasicAuth.xml" result = "text" result = "resulthandler (event)" mistake = "result (incident)" /> & Lt; Mx: button id = "API button" label = "test API command" = "authAndSend (API service)" /> & Lt; Mx: textairia id = "apirtsalt" />
However, a standard Basic Evaluation dialog box still prompts the user for his username and password. I am feeling that I am not doing it right, but all the information I received (flex docs, blogs, Google, etc.) has either not worked or is very vague to help.
Any black magic, oh flex guru? Edit: To set setRemoteCredentials (credentials) to determine () the following action script generates error:
[Messaging error message = 'DirectHTTPChannel ( No proxy) but authentication is not supported. Edit: The problem was resolved, after some attention to Adobe, look for the posts below for a complete explanation. This code will work for arbitrary HTTP authentication headers. Import mx.utils.Base64Encoder; Private function authAndSend (Service: HTTPService): Zero {var encoder: base 64 encoder = new base 64 encoder (); Encoder.InternetNewline = wrong; See the below about why this encoder needs to. Encoded ("someusername: somepassword"); Service.headers = {Authority: "Basic" + Encoder.Ststring ()}; Service.send (); Finally Adobe got some attention and got an answer on it. The problem with long HTTP authentication header is that, by default, the Base64Encoder class will inject newline characters to every 72 characters. Obviously, the base-64 is a part of the encoded string that can be defined as a new header attribute, causing an error. You can fix it (in the example above) encoder.insertNewLines = false; The default setting is correct.
I have fixed the above code to work for an arbitrarily long authentication string.
Comments
Post a Comment