通过一个html页面,调用activex。html页面的charset=gb2312,运行时需要先下载图片到某个盘的文件夹下,现在由于有中文名图片,下载不成功。
function DownloadFile(Source, Dest: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end;
以上是下载写的方法。后来找了点资料改成下面的代码
function DownloadFile(Source, Dest: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(urlencode(utf8encode(source))), PChar(urlencode(utf8encode(Dest))), 0, nil) = 0;
except
Result := False;
end;
end;
还是不行。请大家指教一下有什么好的办法。另说明:应要求中文名文件不能改为英文名
function DownloadFile(Source, Dest: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end;
以上是下载写的方法。后来找了点资料改成下面的代码
function DownloadFile(Source, Dest: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(urlencode(utf8encode(source))), PChar(urlencode(utf8encode(Dest))), 0, nil) = 0;
except
Result := False;
end;
end;
还是不行。请大家指教一下有什么好的办法。另说明:应要求中文名文件不能改为英文名
function DownloadFile(SourceFile, DestFile: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
except
Result := False;
end;
end; procedure TForm1.Button1.Click(Sender: TObject);
const
// URL Location
SourceFile := http://www.google.com/intl/de/images/home_title.gif;
// Where to save the file
DestFile := c:\temp\google-image.gif;
begin
if DownloadFile(SourceFile, DestFile) then
begin
ShowMessage(Download succesful!);
// Show downloaded image in your browser
ShellExecute(Application.Handle,PChar(open),PChar(DestFile),PChar(),nil,SW_NORMAL)
end
else
ShowMessage(Error while downloading + SourceFile)
end;
UrlDownloadToFile(nil, PChar(urlencode(utf8encode(source))), PChar(urlencode(utf8encode(Dest))), 0, nil) = 0;
还是不行吗?
返回的html 用 Utf8ToAnsi
HTTPApp, IdURI TIdURI.URLEncode('http://192.168.0.2/从未试过拥有.APE')
结果:http://192.168.0.2/%E4%BB%8E%E6%9C%AA%E8%AF%95%E8%BF%87%E6%8B%A5%E6%9C%89.APE UTF8ToString(HTTPDecode('http://192.168.0.2/%E4%BB%8E%E6%9C%AA%E8%AF%95%E8%BF%87%E6%8B%A5%E6%9C%89.APE'))
结果: http://192.168.0.2/从未试过拥有.APE
。只不过我在服务端上方的文件名都改成英文名,下载保存到自己电脑上用中文名表示就可以了。