idhttp post 出现exception class EIdSocketError with message 'Socket Error # 10054的解决办法

来源:互联网 发布:飞鹰网络电视 在线 编辑:程序博客网 时间:2024/06/05 16:06
 


    由于项目需要。需要向一个地址提交数据。提交的次数很频繁,但是程序经常raised exception class EIdSocketError with message 'Socket Error # 10054
Connection reset by peer.' 造成程序异常,停止工作。
    于是找到以下解决办法。Exception捕获不到该异常。需要用EIdException来捕获异常。
    IDE环境: Delphi XE3 Version 17.0.4625.53395
    INDY :IDE自带。

  

  v_sparm :TStringList;begin  Result:='0';  v_sparm := TStringList.Create;  ……  Form1.idhtp1.ConnectTimeout := 15000;  Form1.idhtp1.ReadTimeout:=15000;  ……  try    ……    try      Result:=Form1.idhtp1.Post(URL,v_sparm);    except      on e: EIdException do  //用EIdException捕获Socket Error # 10054 Connection reset by peer      begin        WriteLog(e.Message); //处理异常信息。防止程序挂掉。      end;    end;  finally  end;end;