本文整理自网络,侵删。
现在delphi都发布到xe10.1了,tidhttp还有缺陷,那就是超时设置在没有网络或者连不上服务器的时候是无效的,不管你设置为多少都要10-20秒。connectTimeout和readTimeout都试过了,网上找了一圈,有人提出修改源码,我没试,应该也可以。我采用的是把idhttp.get方法放到线程里,在主线程定时检查返回状态,这样就可以控制超时时间了,代码如下。strResult:='';Tthread.CreateAnonymousThread( procedure begin strResult := idhttp.get('url');end).Start; for i := 0 to 4 dobegin if strResult<>'' then break; application.ProcessMessages; Tthread.Sleep(500); application.ProcessMessages;end;
相关阅读 >>
Delphi webbrowser载入自定义html内容并显示
更多相关阅读请进入《Delphi》频道 >>