2011-06-29 32 views
1
our $ua = LWP::UserAgent->new; 
    my $response = $ua->get($url); 
    if($response->is_success) { 
    my $perl_hash_or_arrayref = decode_json(encode("UTF-8", $response->decoded_content)); 

上記のコードは、応答が使用しているエンコーディングを伝える必要なしに、応答をUTF-8エンコーディングに変換します。LWP :: UserAgentは自動的に文字セットを検出できますか?

これは、特定のケースで失敗する可能性があります。

応答コードをLWP::UserAgentに明示的に伝えることはできますか?

答えて

2

HTTP::Messagedecoded_contentのためのドキュメントを参照してください。

$ mess-> decoded_content(%オプション)

Returns the content with any Content-Encoding undone and for 
textual content the raw content encoded to Perl's Unicode strings. 
If the Content-Encoding or charset of the message is unknown this 
method will fail by returning undef. 

    The following options can be specified. 

    charset 

     This override the charset parameter for text content. The value 
none can used to suppress decoding of the charset. 
+0

'メッセージのコンテンツのエンコーディングや文字セットがこの 不明な場合メソッドはundefを返すことによって失敗します.'しかし、実際には、私は内部を知らないだけです。 –

+0

@new_perl:LWPは、あなたが話しているHTTPサーバによって送信された 'Content-Encoding'と' Charset' HTTPヘッダを調べます。 – friedo

関連する問題