How can I avoid the authentication dialog in Flex when using HTTPService or URLRequest?

This is related to this question . I am writing a Flex Application (WindowedApplication) that uses REST. It's okay when I submit with strong authentication, but if I accidentally pass in an invalid username or password for a REST API (such as a REST REST API), an authentication dialog will pop up.

This is an unwanted user experience and it happens both when using the HTTPService and in the URLRequest. It seems that the event I can catch does not cancel the dialog.

This is what my code looks like:

    var request:URLRequest = new URLRequest('http://twitter.com/statuses/update.json');
    request.method = URLRequestMethod.POST;
    var encoder : Base64Encoder = new Base64Encoder();
    encoder.encode(this.user + ':' + this.password);
    request.requestHeaders.push(new URLRequestHeader("Authorization", "Basic " + encoder.toString()));
    var params:Object = new Object();
    params.status = msg;                
    request.data = params;

    var loader:URLLoader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, HandleRequestComplete);
    loader.load(request);

      

Am I missing something? Is there a better way to approach this?

+1


source to share


3 answers


From the Twitter API here :



suppress_response_codes: If this parameter is present, all responses will be returned with a 200 OK code status - even errors. This parameter exists to host Flash and JavaScript applications running in browsers that intercept all non-200 responses. If used, then it is up to the client to determine the error by analyzing the response body. Use with caution, as this error message may vary.

+1


source


This is because your URLRequest is handling authentication. To avoid this, do the following:

request.authenticate = false;

      



Hello!

Alain.

+2


source


I don't know if this works in a regular Flex application, but in AIR applications you can set a list of allowed response codes to be considered valid.

0


source







All Articles