Google主页的编码是什么?

时间:2010-03-18 15:15:22

标签: perl firefox

当Google的主页与Firefox或Chrome通信时,它使用特定类型的编码(Perl称它为utf.64)。但是,我不能使用这样解码它;这是一个gzipped enconding?我需要在Perl中完成一个应该能够使用Firefox(如代理)理解Google主页的应用程序。

2 个答案:

答案 0 :(得分:6)

使用LiveHTTPHeaders:

http://www.google.com/

GET / HTTP/1.1
Host: www.google.com
User-Agent: ***
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.7,tr;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: UTF-8,*
Keep-Alive: 115
Connection: keep-alive
Cookie: ***

HTTP/1.1 200 OK
Date: Thu, 18 Mar 2010 15:29:03 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=UTF-8
Content-Encoding: gzip
Server: gws
Content-Length: 4440
X-XSS-Protection: 0

表示返回的数据是gzip压缩的,使用的字符编码是UTF-8。

#!/usr/bin/perl

use strict; use warnings;
use LWP::UserAgent;

my $ua = LWP::UserAgent->new();
$ua->show_progress(1);

my $response = $ua->get('http://google.com/');

if ( $response->is_success ) {
    print $response->decoded_content, "\n";
}

答案 1 :(得分:3)

假设您正在使用LWP或兼容的东西,请使用HTTP::Message::decoded_content。内容编码和字符编码都是自动计算出来的。