1
votes

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

3

3 Answers

3
votes

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.

2
votes

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.

0
votes

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");
}