以前用d7、indy9写的程序:用两个函数实现客户端读取服务器端的asp程序生成的xml,一直没什么问题,现在用xe2,用了utf8toansi,utf8decode都会出现乱码,用浏览器却可以正常显示,不知道怎么解决了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;
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;
解决方案 »
- 比较头疼的问题,MDI子窗体如何去除边框
- 悬赏100,如何把记录插入到中间的物理地址或如何按主键排序访问表
- 如何实数转换为整数?快回答!限3分钟内回答,否则不给分!
- 打開主從關系的兩個adoquery(8個字段﹐有一text字段)﹐adoquery2(10個字段﹐有一text字段),速度極慢﹐耗用內存達20多M
- 请教我的delphi编译时出现找不到xls控件,请问是何控件啊,在哪里下载
- 怎样在程序中打开PowerPoint文件或者Word文件?
- 谁知道比较好介绍windows运行机制(消息、句柄等)的网站
- 关于代码的颜色问题!!!
- 请问在做安装程序时,如何判断哪些DLL要打包进去????
- MDI 如何使MDIChild 显示在 Design位置 (Just here waiting)
- idhttp.post文字为乱码
- 安装ICS控件后,出现属性不存在,这个是什么错误?
result:=utf8toansi(idhttp.Post(url,sends));
服务器端是utf8。都不好用,不知道为什么呢?
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;
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;这是利用服务器端的ASP程序获得和保存数据。不过,在分页的时候又遇到了问题,后来又利用服务器端的webservice的方法把所有的问题都解决了!