5,927
社区成员




//根据URl,发送Http get请求,得到Xml的对象或String的通用函数
function getReturn(urlStr :string; RtlType :String; var XmlDoc :TXmlDocument; var Rlt_Str :String) :Boolean;
var IdHTTP1 :TIdHTTP; RtnStream :TMemoryStream;
begin
Result :=false;
IdHTTP1 :=Tidhttp.Create(nil);
try
with IdHTTP1 do begin
Request.Accept :='text/html, */*';
Request.ContentLength :=0;
Request.ContentRangeEnd :=0;
Request.ContentRangeStart :=0;
Request.UserAgent :='Mozilla/3.0 (compatible; Indy Library)';
end;
try
RtnStream :=TMemoryStream.Create;
IdHTTP1.get(urlStr, RtnStream);
Rlt_Str :=StreamToStr(RtnStream); //得到string
except
on E: Exception do begin
Msg(e.Message, 0, 0); RtnStream.free; idhttp1.Disconnect; idhttp1.Free; Exit;
end;
end;
finally
RtnStream.free; idhttp1.Disconnect; idhttp1.Free;
end;
Result :=true;
end;
URL的例子: