Copy link to clipboard
Copied
Hi all,
I'm developing an AIR application that logs me into a web service (I click a "Login" button and the application submits an HTML form on my behalf). However, if the application hasn't been executed for a while—half a day or so—it always dispatches IOErrorEvent with the following error when I try to log in:
Error #2032: Stream Error.
If I immediately try to log in again, I'm connected/authenticated without any problem. If I close the application and run it again shortly thereafter, the problem does not occur. It only happens when I run the application for the first time after about 6-12 hours.
A lot of Google results blame caching, so I'm doing everything I can to avoid caching but the problem persists. The relevant portion of my code is below. Am I doing anything wrong? Has anyone else seen this very strange behavior?
var params:URLVariables = new URLVariables();
params.user = "username";
params.pass = "password";
var request:URLRequest = new URLRequest(Site.LOGIN_URL);
request.data = params;
request.method = URLRequestMethod.POST;
request.useCache = request.cacheResponse = false;
request.requestHeaders.push(new URLRequestHeader("Cache-Control", "no-store"));
request.requestHeaders.push(new URLRequestHeader("Pragma", "no-cache"));
var requestLoader:URLLoader = new URLLoader();
requestLoader.addEventListener(IOErrorEvent.IO_ERROR, requestFailed);
requestLoader.addEventListener(Event.COMPLETE, requestSucceeded);
requestLoader.load(request);
Copy link to clipboard
Copied
hi
not sure if the request headers will make much difference a common technique to avoid caching is to add extra chars to the end of a url (eg: google.com?1234) so it is always unique (to fool browser/isp into thinking its a different url). First extra char should always be a "?"
for your code you could do this:
var request:URLRequest = new URLRequest(Site.LOGIN_URL+"?"+getTimer().toString());
which will add a unique number to end of url (ie millisecs since 1970)
Copy link to clipboard
Copied
Thanks, I actually have tried that technique to no avail (I should have mentioned that as one of the things I've done in attempting to avoid caching). I've also tried changing my Flash Builder framerwork linkage settings to "Merged into code", and I've tried immediately loading the URL again after the first failure.
Any other suggestions? Has anyone else seen this and overcome it?
Copy link to clipboard
Copied
I found a workaround! I thought I'd post it in case it helps someone else.
Very simply, my workaround is to get the problem out of the way by first loading a different page on the site (one that doesn't require authentication) and kicking off a timer. When the load is finished, and whether it succeeded or failed (in my testing thus far it always fails), I set a flag (Boolean variable) to indicate that the first attempt is done. Every few seconds, my timer is checking this flag to see if the failed attempt is done. When the failed attempt is done, I load the actual page I want, and the problem does not occur!
Obviously this is a total hack to work around something strange on my server (or perhaps an Adobe bug), but it is acceptable.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more