2,497
社区成员
发帖
与我相关
我的任务
分享
function GetdataAsp(AspName:string; StrSql:String):WideString;
begin
try
ConnectUrl := 'Http://'+ConnectIni+AspName;
ReSult := postXml(StrSql,ConnectUrl);
except
on Ex:exception do
begin
ShowMessage(Ex.Message);
assignfile(ErrorF,ExtractFilePath(Application.exename)+'ErrorMessage.txt');
Append(ErrorF);
try
writeln(ErrorF,DateTimeToStr(now)+' | '+Ex.Message);
finally
closefile(ErrorF);
end;
end;
end;
end;
function postXml(const xmlstr, url: WideString): WideString;
var
idHttp:TIdHTTP;
sends:tstrings;
IdEncoderMIME1:TIdEncoderMIME;
vStream: TMemoryStream;
begin
result:='';
try
idHttp:= TIdHTTP.Create(nil);
idHttp.Request.ContentType := 'application/x-www-form-urlencoded';
idhttp.Request.AcceptCharSet := 'UTF-8';
idhttp.Request.AcceptEncoding := 'UTF-8';
idhttp.Request.AcceptLanguage := 'UTF-8';
sends:=tstringlist.Create;
sends.Add('strSQL='+(xmlstr));
result:=idhttp.Post(url,sends);
except
on Ex:exception do
begin
assignfile(ErrorF,ExtractFilePath(Application.exename)+'ErrorMessage.txt');
Append(ErrorF);
try
writeln(ErrorF,DateTimeToStr(now)+' | '+Ex.Message);
finally
closefile(ErrorF);
end;
end;
end;
idHttp.Free;
sends.Free;
function GetdataAsp(AspName:string; StrSql:string):string;
var
ErrorF:TEXTFILE;
idHttp:TIdHTTP;
sends:Tstrings;
ResponseStream:TStringStream;
begin
ConnectUrl := 'Http://'+ConnectIni+AspName;
try
// ResponseStream:=TStringstream.Create('',936); //gb2312编码
ResponseStream:=TStringstream.Create('',TEncoding.UTF8);
idHttp:= TIdHTTP.Create(nil);
idhttp.AllowCookies := false;
idhttp.HandleRedirects := false ;
idHttp.Request.ContentType := 'application/x-www-form-urlencoded';
// idHttp.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
// idHTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)';
// idhttp.Request.AcceptCharSet := 'gb2312';
// idhttp.Request.ContentEncoding := 'gb2312';
// idhttp.Request.ContentLanguage := 'gb2312';
// idhttp.Request.AcceptLanguage := 'utf-8';
sends:=tstringlist.Create;
sends.Add('strSQL='+AnsiString(StrSql));
idhttp.Post(ConnectUrl,sends,ResponseStream);
result:=ResponseStream.DataString;
except
on Ex:exception do
begin
assignfile(ErrorF,ExtractFilePath(Application.exename)+'ErrorMessage.txt');
Append(ErrorF);
try
writeln(ErrorF,DateTimeToStr(now)+' | '+Ex.Message);
finally
closefile(ErrorF);
end;
end;
end;
Freeandnil(ResponseStream);
idHttp.Free;
sends.Free;
end;
function postXml(var xmlstr, url: String): String;
var
idHttp:TIdHTTP;
sends:Tstrings;
ErrorF:TEXTFILE;
ResponseStream:TStringStream;
begin
result:='';
try
ResponseStream:=TStringstream.Create('',936);
idHttp:= TIdHTTP.Create(nil);
idhttp.AllowCookies := false;
idhttp.HandleRedirects := false ;
idHttp.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)';
sends:=tstringlist.Create;
sends.Add('strSQL='+(xmlstr));
idhttp.Post(url,sends,ResponseStream);
result:=ResponseStream.DataString;
except
end;
Freeandnil(ResponseStream);
idHttp.Free;
sends.Free;
end;