F
fjjiantuo
Unregistered / Unconfirmed
GUEST, unregistred user!
若文件名含有中文,则从服务器收到以下 HTTP 状态消息: 404 File Not Found 我参照http://support.microsoft.com/kb/930268/zh-cn解决 function TOaUp.HttpDownloadFile(const URL, strLocalFile: string): string;
const Agent = 'Internet Explorer';
SEGMENT_LENGTH = 1024 * 64;
var hFile, HInet: HINTERNET;
Buffer: array[0..SEGMENT_LENGTH] of Char;
BufRead: Cardinal;
BufSize: Cardinal;
ret: BOOL;
URL3: PChar;
lpszBuffer: PChar;
lpdwBufferLength: DWORD;
dwFlags: DWORD;
iFile: Integer;
begin
If FileExists(strLocalFile) then
begin
DeleteFile(strLocalFile);
Sleep(500);
end;
iFile := FileCreate(strLocalFile);
HInet := InternetOpen(PChar(Agent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(HInet) then
try URL3:=PChar(URL);
lpdwBufferLength := INTERNET_MAX_URL_LENGTH;
ret:=InternetCanonicalizeUrl(URL3,lpszBuffer,lpdwBufferLength,dwFlags);
If ret then
begin
ShowMessage(URL3+'ok'+lpszBuffer);
end;
hFile := InternetOpenUrl(HInet,lpszBuffer, nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(hFile) then
try BufSize := SizeOf(Buffer);
with TStringStream.Create('')do
try while InternetReadFile(hFile, @Buffer, BufSize, BufRead) and (BufRead > 0)do
begin
FileWrite(iFile, Buffer, BufRead);
end;
finally Free;
FileClose(iFile);
end;
finally InternetCloseHandle(hFile);
end;
finally InternetCloseHandle(hinet);
end;
end;
文中文件还是不行,并有一个错误提示:acess violation at address 6d657442f.read of address 6d65742f
const Agent = 'Internet Explorer';
SEGMENT_LENGTH = 1024 * 64;
var hFile, HInet: HINTERNET;
Buffer: array[0..SEGMENT_LENGTH] of Char;
BufRead: Cardinal;
BufSize: Cardinal;
ret: BOOL;
URL3: PChar;
lpszBuffer: PChar;
lpdwBufferLength: DWORD;
dwFlags: DWORD;
iFile: Integer;
begin
If FileExists(strLocalFile) then
begin
DeleteFile(strLocalFile);
Sleep(500);
end;
iFile := FileCreate(strLocalFile);
HInet := InternetOpen(PChar(Agent), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(HInet) then
try URL3:=PChar(URL);
lpdwBufferLength := INTERNET_MAX_URL_LENGTH;
ret:=InternetCanonicalizeUrl(URL3,lpszBuffer,lpdwBufferLength,dwFlags);
If ret then
begin
ShowMessage(URL3+'ok'+lpszBuffer);
end;
hFile := InternetOpenUrl(HInet,lpszBuffer, nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(hFile) then
try BufSize := SizeOf(Buffer);
with TStringStream.Create('')do
try while InternetReadFile(hFile, @Buffer, BufSize, BufRead) and (BufRead > 0)do
begin
FileWrite(iFile, Buffer, BufRead);
end;
finally Free;
FileClose(iFile);
end;
finally InternetCloseHandle(hFile);
end;
finally InternetCloseHandle(hinet);
end;
end;
文中文件还是不行,并有一个错误提示:acess violation at address 6d657442f.read of address 6d65742f