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);//url要寫全 http://www.123.com
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;
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
begin
s:=GetWebPage('http://www.bjfcdt.gov.cn/datacenter/gettvplusinfo.aspx');
ShowMessage(s);
end;
提取出来的是乱码,我运行的是delphi2010版
是哪里出问题了?
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);//url要寫全 http://www.123.com
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;
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
begin
s:=GetWebPage('http://www.bjfcdt.gov.cn/datacenter/gettvplusinfo.aspx');
ShowMessage(s);
end;
提取出来的是乱码,我运行的是delphi2010版
是哪里出问题了?
function Utf8Encode(const WS: WideString): UTF8String;
var
L: Integer;
Temp: UTF8String;
begin
Result := '';
if WS = '' then Exit;
SetLength(Temp, Length(WS) * 3); // SetLength includes space for null terminator L := UnicodeToUtf8(PChar(Temp), Length(Temp)+1, PWideChar(WS), Length(WS));
if L > 0 then
SetLength(Temp, L-1)
else
Temp := '';
Result := Temp;
end;
运行不了
Checking project dependencies...
Compiling Project1.dproj (Debug configuration)
[DCC Warning] Unit1.pas(43): W1036 Variable 'dwFileSize' might not have been initialized
[DCC Warning] Unit1.pas(42): W1036 Variable 'szSizeBuffer' might not have been initialized
[DCC Warning] Unit1.pas(61): W1044 Suspicious typecast of UTF8String to PWideChar
[DCC Error] Unit1.pas(61): E2250 There is no overloaded version of 'UnicodeToUtf8' that can be called with these arguments
[DCC Warning] Unit1.pas(61): W1000 Symbol 'UnicodeToUtf8' is deprecated
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
Failed
Elapsed time: 00:00:00.461行 : L := UnicodeToUtf8(PChar(Temp), Length(Temp)+1, PWideChar(WS), Length(WS));