获取,用于 TChromium 的良好编码 URL
Get, a good encoded URL for TChromium
Whith TWebBrowser
基于 Internet Explorer URL 未加密,例如我可以简单地去:
path:='file:///C:/##Project/Page.html
WebBrowser1.Navigate(path);
但是,对于 TChromium
组件 URL 编码为:
path:='file:///D:/%23%23Project/Page.html
chrm1.Browser.MainFrame.LoadUrl(path);
这是一个问题,因为在程序中我创建路径 (URL) 使用:
path := ExtractFilePath(Application.ExeName)+ 'Page.html';
并且 chromium 无法识别路径,因为它没有正确编码。
更新:
我安装了 DCEF3,以下对于 GuiClient 演示中的特定路径工作正常:
Path := StringReplace(Path, '#', '%23', [rfReplaceAll]);
crm.Browser.MainFrame.LoadUrl(Path);
我也试过了
Path := TIdURI.UrlEncode(Path);
但是路径值保持不变(在 D7 中)。因此,对于比我的 StringReplace 解决方案更通用的解决方案,您可能想看看 Hugh Jones gave a link to,
中的一些答案
whosebug.com/questions/776302/standard-url-encode-function
[原创]
我没有安装 DCEF3 来检查,但看起来你需要这样做
path := ExtractFilePath(Application.ExeName)+ 'Page.html';
path := HttpEncode(Path);
chrm1.Browser.MainFrame.LoadUrl(path);
将 HttpApp 添加到您的 Uses 之后。
编码上面的函数都可以,但是它们的编码方式不同。
Tchromium 需要一个真正特定的、足够特定的,以至于无法创建典型的功能。
HttpEncode
几乎完美地工作,但编码特殊字符,如 +、- 等
我试试作者的功能:
whosebug.com/questions/776302/standard-url-encode-function
然后我尝试
function MyEncodeUrl(source: string): string;
var i:integer;
begin
result := '';
for i := 1 to length(source) do
if not (source[i] in ['A'..'Z','a'..'z','0','1'..'9','-','_','~','.']) then result := result + '%'+inttohex(ord(source[i]),2) else result := result + source[i];
end;
但是,我在“/”之间的片段上使用上面的函数,例如:
path := ExtractFilePath(Application.ExeName) ;
function GenerateURL(path: string): string;
var after,temp: string;
begin
path:= ExtractFilePath(Application.ExeName);
after:=Copy(path,1,4);
Delete(path,1,3);
while (Pos('\',path)>0 )do
begin
wynik:=Copy(path,1,Pos('\',path)-1);
if Length(temp)<>0 then
temp:=MyEncodeUrl(temp)+'\';
Insert(temp,after,Length(s));
Delete(path,1,Pos('\',path))
end ;
Delete(after,(Length(after)),1);
Result := StringReplace(after, '\', '/', [rfReplaceAll]);
end;
在上面的函数之后,我只是添加了 URL 函数的开头和结尾:
URL := 'file:///' + GenerateUrl(path)+ 'page.htm';
感谢大家的帮助
Whith TWebBrowser
基于 Internet Explorer URL 未加密,例如我可以简单地去:
path:='file:///C:/##Project/Page.html
WebBrowser1.Navigate(path);
但是,对于 TChromium
组件 URL 编码为:
path:='file:///D:/%23%23Project/Page.html
chrm1.Browser.MainFrame.LoadUrl(path);
这是一个问题,因为在程序中我创建路径 (URL) 使用:
path := ExtractFilePath(Application.ExeName)+ 'Page.html';
并且 chromium 无法识别路径,因为它没有正确编码。
更新:
我安装了 DCEF3,以下对于 GuiClient 演示中的特定路径工作正常:
Path := StringReplace(Path, '#', '%23', [rfReplaceAll]);
crm.Browser.MainFrame.LoadUrl(Path);
我也试过了
Path := TIdURI.UrlEncode(Path);
但是路径值保持不变(在 D7 中)。因此,对于比我的 StringReplace 解决方案更通用的解决方案,您可能想看看 Hugh Jones gave a link to,
中的一些答案whosebug.com/questions/776302/standard-url-encode-function
[原创]
我没有安装 DCEF3 来检查,但看起来你需要这样做
path := ExtractFilePath(Application.ExeName)+ 'Page.html';
path := HttpEncode(Path);
chrm1.Browser.MainFrame.LoadUrl(path);
将 HttpApp 添加到您的 Uses 之后。
编码上面的函数都可以,但是它们的编码方式不同。
Tchromium 需要一个真正特定的、足够特定的,以至于无法创建典型的功能。
HttpEncode
几乎完美地工作,但编码特殊字符,如 +、- 等
我试试作者的功能: whosebug.com/questions/776302/standard-url-encode-function
然后我尝试
function MyEncodeUrl(source: string): string;
var i:integer;
begin
result := '';
for i := 1 to length(source) do
if not (source[i] in ['A'..'Z','a'..'z','0','1'..'9','-','_','~','.']) then result := result + '%'+inttohex(ord(source[i]),2) else result := result + source[i];
end;
但是,我在“/”之间的片段上使用上面的函数,例如:
path := ExtractFilePath(Application.ExeName) ;
function GenerateURL(path: string): string;
var after,temp: string;
begin
path:= ExtractFilePath(Application.ExeName);
after:=Copy(path,1,4);
Delete(path,1,3);
while (Pos('\',path)>0 )do
begin
wynik:=Copy(path,1,Pos('\',path)-1);
if Length(temp)<>0 then
temp:=MyEncodeUrl(temp)+'\';
Insert(temp,after,Length(s));
Delete(path,1,Pos('\',path))
end ;
Delete(after,(Length(after)),1);
Result := StringReplace(after, '\', '/', [rfReplaceAll]);
end;
在上面的函数之后,我只是添加了 URL 函数的开头和结尾:
URL := 'file:///' + GenerateUrl(path)+ 'page.htm';
感谢大家的帮助