Background: I've been drafted to maintain and update a flash/flex/as3 front-end to website using php on the backend. I'm getting better at it, but I'm still new to the environment.
I need some processed information received back in the return handler of a POST. I thought it would be clever to do the next POST within the return handler. In other words, I've got something like this:
private function finishThis():void
{
var s:HTTPService = new HTTPService();
rq.action = "do_something";
s.url = "inc/php/test.php";
s.method = "POST";
s.request = rq;
s.requestTimeout = 120000;
s.addEventListener(ResultEvent.RESULT, doSomethingRH);
s.send();
s.disconnect(); // That's a test, it didn't help
}
and then in doSomethingRH(), I've got
private function doSomethingRH(event:ResultEvent):void
{
doSomethingElse();
}
private function doSomethingElse():void
{
var s:HTTPService = new HTTPService();
rq.action = "do_something_else";
s.url = "inc/php/test.php";
s.method = "POST";
s.request = rq;
s.requestTimeout = 120000;
s.addEventListener(ResultEvent.RESULT, doSomethingElseRH);
s.send();
s.disconnect(); // That's new, it wasn't there before
}
All of this works as expected using http://localhost (WAMP). But online, though I have backend indications that function do_something_else
runs (so far), but function doSomethingElseRH()
never gets called. Instead, I get the error I've seen from several posts :
[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2
text="Error #2032: Stream Error
. URL: http://test.net/inc/php/test.php"].
URL: http://test.net/inc/php/test.php"]
The problem pointed out most often is too many simultaneous connections. I don't need to do multiple connections, but thought perhaps I had them since I was starting the new POST in the previous POST return handler. Instead of calling doSomethingElse() directly, I added an event and did a dispatchEvent() to call it, but at least according to the call stack shown in FlashDevelop, the eventual call to doSomethingElse() was under the doSomethingRH() function (still learning this stuff). And all of that is conjecture based on a post I saw about getting the HTTPService instance from within event delivered to the return handler.
My ultimate question is, how can I achieve sequential POSTs like this without the error?
And if I'm getting the error because of the way I'm chaining them together, is there a clean-up function I can do so that when the return handler is called, the connection can be fully closed?
Update - it's fine
A pdf engine was being called within both functions, one to create a base file, the other to append some pages. It was working fine, but was updated recently. Blocking those activities allowed the http flow to work as expected, no disconnect() needed.
The best I can say for this is it's an example of chaining calls together that I haven't seen online, I suppose that's something.
Stream Error
means "file not found". So on your servertest.net
make sure there exists a folder calledinc
with sub-folderphp
and in that sub-folder you put thetest.php
. Also some servers have a specific folder for running PHP scripts from, so check that your file is in right place... – VC.One