Question

This is related to this question. I'm writing a Flex app (a WindowedApplication) that uses REST. Everything's fine when I post with valid authentication, but if I happen to pass an invalid username or password to the REST API (a Twitter REST API, to be specific), an authentication dialog pops up.

That's not a desirable user experience, and it happens both when I use HTTPService and URLRequest. There doesn't seem to be an event I can catch to cancel the dialog.

Here's 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?

Was it helpful?

Solution

From the Twitter API Doc here:

suppress_response_codes: If this parameter is present, all responses will be returned with a 200 OK status code - even errors. This parameter exists to accommodate Flash and JavaScript applications running in browsers that intercept all non-200 responses. If used, it's then the job of the client to determine error states by parsing the response body. Use with caution, as those error messages may change.

OTHER TIPS

That is becouse your URLRequest is handling authentication. To avoid that do the next:

request.authenticate = false;

Regards!

Alain.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top