delphi的connection closed Gracefully错误

xiaoxiao2021-02-28  31

 

将这个放到调用页面上....一个处理地址函数..

function GetWebPage(URL: string):string;

var

  IDHTTP: TIDHttp;

  ss: String;

begin

  IDHTTP:= TIDHTTP.Create(nil);

  try

    try

        idhttp.Disconnect;

        idhttp.HandleRedirects:= true;   //必须支持重定向否则可能出错

        idhttp.ReadTimeout:= 30000;     //超过这个时间则不再访问

        ss:=idhttp.Get(url);

        //ss:=UTF8ToAnsi( ss);                  //UTF8编码转换

        if IDHTTP.ResponseCode=200 then

        Result := ss;

    except

        //ss:='';

    end;

  finally

    IDHTTP.Free;

  end;

end;

 

===========================================================

注意:

get百度时,需要修改http头: User-Agent: Mozilla/3.0 (compatible; Indy Library)   因为百度屏蔽了 ‘Indy Library’ 这个客户端标识的。

转载请注明原文地址: https://www.6miu.com/read-35557.html

最新回复(0)