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