• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

delphi函数,识别字符集编码

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

纪念不用 Delphi 开发7周年

 函数,获取web page文本,识别字符集编码;

 1 function CreateHttpRequest(proxyServer: string = ''; proxyPort: integer = 0):
 2   TIdHTTP;
 3 function DecodeHttpRequestText(InString: string): string;
 4 implementation
 5 
 6 {$R *.dfm}
 7 
 8 function DecodeHttpRequestText(InString: string): string;
 9 begin
10   Result := UpperCase(InString);
11   //google,baidu,cnblogs,localhost等测试ok...
12   if (Pos('CHARSET=', Result) = 0or (pos('=UTF-', Result) <> 0then
13     InString := Utf8Decode(InString);
14   Result := InString;
15 end;
16 
17 function CreateHttpRequest(proxyServer: string = ''; proxyPort: integer = 0):
18   TIdHTTP;
19 begin
20   Result := TIdHTTP.Create(nil);
21   with Result do
22   begin
23     HandleRedirects := true;
24     HTTPOptions := [hoForceEncodeParams];
25     ReadTimeout := 30000;
26     Request.Accept :=
27       'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*';
28     Request.AcceptLanguage := 'zh-cn';
29     Request.ContentType := 'application/x-www-form-urlencoded';
30     Request.UserAgent :=
31       'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 4.0)';
32     if (proxyServer <> ''then
33       proxyParams.ProxyServer := proxyServer; //'代理服务器地址';
34     if proxyPort <> 0 then
35       proxyParams.ProxyPort := proxyPort; //'代理服务器端口';
36   end;
37 end;
38 
39 procedure TForm1.btn1Click(Sender: TObject);
40 var
41   getstr: string;
42 begin
43   mmo1.Lines.Clear;
44   getstr :=DecodeHttpRequestText( CreateHttpRequest().Get(edt1.Text));
45   mmo1.Lines.Add(getstr);
46 
47 end;

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
QQ面板实现方法(delphi)(一)发布时间:2022-07-18
下一篇:
DesignPattern----26.Behavioral.TemplateMethod.Pattern(DelphiSample)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap