代码之家  ›  专栏  ›  技术社区  ›  sc45

httpService请求超时

  •  1
  • sc45  · 技术社区  · 17 年前

    如何确定httpService实例是否超时?谢谢!

    3 回复  |  直到 15 年前
        1
  •  2
  •   Diego Dias    17 年前

    如果设置了RequestTimeout,那么当请求超时时,它将引发一个错误。因此,您只需将事件侦听器添加到httpservice faultevent。

        2
  •  3
  •   Bryan Hunt    15 年前

    请注意httpservice的这种迷人的局限性…

    如果您设置了http.requestTimeout方法,它将静默地忽略您请求它作为post请求的事实,并丢弃任何和所有头。

    出于某种原因,在flex中,获取转储所有头文件。

    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();
    

    哦,是的,设置method=“post”两次是有意的,更有趣的是,如果您在调试器中运行它,当它到达最后一行时,http.send(),并且查看对象的内部状态,它仍然被设置为post请求…

    木偶。

        3
  •  0
  •   RJ Owen    15 年前

    从flex 4.5(可能更早)开始,对于超时错误,故障事件上有一个特定的故障代码:

    在故障处理程序中:

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