sc45
sc45

Reputation: 1956

HttpService requestTimeout

How do I determine if the HttpService instance timed out? Thanks!

Upvotes: 1

Views: 5557

Answers (3)

RJ Owen
RJ Owen

Reputation: 615

As of Flex 4.5 (possibly earlier) there's a specific fault code on the fault event for timeout errors:

In your fault handler:

if(faultEvent.fault.faultCode == "Client.Error.RequestTimeout"){
  trace("TIMEOUT ERROR");
}

Upvotes: 0

Bryan Hunt
Bryan Hunt

Reputation: 3783

Be aware of this charming limitation of HTTPService ...

If you set the http.requestTimeout method, it will silently ignore the fact you asked it to be a POST request and discards any and all headers.

For some reason, in Flex, GET dumps all headers.

var http:HTTPService = new HTTPService()
http = new HTTPService();
http.method = "POST";
http.addEventListener(ResultEvent.RESULT, result*emphasized text*Handler);
http.addEventListener(FaultEvent.FAULT, resultHandler);
http.url = "http://www.example.com/post;

//http.requestTimeout = 5; //Watch out for this, there go the headers...

http.method = "POST";
http.send();

Oh yes, setting method = "POST" twice was intentional, what's even funnier is, if you run it in the debugger, when it comes to the last line, http.send(), and you look at the object's internal state, it's still set to be a POST request...

Muppets.

Upvotes: 3

Diego Dias
Diego Dias

Reputation: 22606

If you set requestTimeout then your request will raise a fault when it times out. So you can just add an event listener to the httpservice faultevent.

Upvotes: 2

Related Questions