DELPHI获取网页内容
从网上下了这个函数,但发现这个函数有时读取网页内容时,会读出乱码(不是中文)。functionGetWebPage(constUrl:string):string;var...
从网上下了这个函数,但发现这个函数有时读取网页内容时,会读出乱码(不是中文)。
function GetWebPage(const Url: string): string;
var
Session,
HttpFile: HINTERNET;
szSizeBuffer: Pointer;
dwLengthSizeBuffer: DWord;
dwReserved: DWord;
dwFileSize: DWord;
dwBytesRead: DWord;
Contents: pchar;
begin
Session := InternetOpen('', 0, nil, nil, 0);
HttpFile := InternetOpenUrl(Session, pchar(Url), nil, 0, 0, 0);
dwLengthSizeBuffer := 1024;
HttpQueryInfo(HttpFile, 5, szSizeBuffer, dwLengthSizeBuffer, dwReserved);
GetMem(Contents, dwFileSize);
InternetReadFile(HttpFile, Contents, dwFileSize, dwBytesRead);
InternetCloseHandle(HttpFile);
InternetCloseHandle(Session);
Result := StrPas(Contents);
FreeMem(Contents);
end;
s := trim(GetWebPage(Load_web_update + '/SysUpFiles.htm'));
网页显示的内容为V20090220111120 ,结果S的值确是'V-'#$A0
怎试也不行,请高手说说中间那里出错了? 展开
function GetWebPage(const Url: string): string;
var
Session,
HttpFile: HINTERNET;
szSizeBuffer: Pointer;
dwLengthSizeBuffer: DWord;
dwReserved: DWord;
dwFileSize: DWord;
dwBytesRead: DWord;
Contents: pchar;
begin
Session := InternetOpen('', 0, nil, nil, 0);
HttpFile := InternetOpenUrl(Session, pchar(Url), nil, 0, 0, 0);
dwLengthSizeBuffer := 1024;
HttpQueryInfo(HttpFile, 5, szSizeBuffer, dwLengthSizeBuffer, dwReserved);
GetMem(Contents, dwFileSize);
InternetReadFile(HttpFile, Contents, dwFileSize, dwBytesRead);
InternetCloseHandle(HttpFile);
InternetCloseHandle(Session);
Result := StrPas(Contents);
FreeMem(Contents);
end;
s := trim(GetWebPage(Load_web_update + '/SysUpFiles.htm'));
网页显示的内容为V20090220111120 ,结果S的值确是'V-'#$A0
怎试也不行,请高手说说中间那里出错了? 展开
展开全部
//试下用idhttp
uses IdHTTP;
function GetWebPage(const Url :string; IsUtf8 :Boolean = False):string;
var
idp :TIdHTTP;
begin
Result := '';
idp := TIdHTTP.Create(Application);
try
idp.HandleRedirects := True;
idp.Request.UserAgent := 'Mozilla/5.0';
Result := idp.Get(Url);
if IsUtf8 then
Result := Utf8ToAnsi(Result);
finally
FreeAndNil(idp);
end;
end;
//当网页编码是utf8时,第2个参数请为true,要不汉字会出现乱码
ShowMessage(GetWebPage(Load_web_update + '/SysUpFiles.htm'));
uses IdHTTP;
function GetWebPage(const Url :string; IsUtf8 :Boolean = False):string;
var
idp :TIdHTTP;
begin
Result := '';
idp := TIdHTTP.Create(Application);
try
idp.HandleRedirects := True;
idp.Request.UserAgent := 'Mozilla/5.0';
Result := idp.Get(Url);
if IsUtf8 then
Result := Utf8ToAnsi(Result);
finally
FreeAndNil(idp);
end;
end;
//当网页编码是utf8时,第2个参数请为true,要不汉字会出现乱码
ShowMessage(GetWebPage(Load_web_update + '/SysUpFiles.htm'));
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |