簡體   English   中英

LWP 響應 JSON 值為空

[英]LWP response JSON values are empty

I'm trying to run GET method using LWP and CURL (unix command) to get the content in JSON format, I'm seeing the complete content only in CURL command but the LWP response is showing valid JSON but with empty values.

要求

輕量化

   my $ua= LWP::UserAgent->new();
   my $host='https://sample.com/iersiefhsiof';
   $ua->default_header('Content-Type' => 'application/json');
   $ua->default_header('Authorization' => 'XXXXXXXXXXXXXXxx');
   $ua->default_header('Accept' => 'application/json');
   my $response=$ua->get($host);
   $res=$response->content();
   print ($res);

CURL

curl  -H "Accept: application/json" -H "Content-Type: application/json" -H 'Authorization:XXXXXXXXXXXXXXX' -ikL 'https://sample.com/iersiefhsiof'

回復

輕量化

{
    "id":"",
    "state":"",
    "category":"",
    "severity":"",}'`

CURL

  `{"id":"iersiefhsiof","state":"open","category":"App","severity":"minor",}'`

請幫助我了解我在 LWP 請求中缺少什么以獲得完整的響應內容。

現在已經修好了!

根據 Header.pm,我應該使用“:”作為自定義 header 字段名稱,如果我不使用它,那么它將第一個字符轉換為大寫,因此缺少 Z099FB995346F31C749F6E40DB0F9。

    unless ($field =~ /^:/) {
    $field =~ tr/_/-/ if $TRANSLATE_UNDERSCORE;
    my $old = $field;
    $field = lc $field;
    unless($standard_case{$field} || $self->{'::std_case'}{$field}) {
        # generate a %std_case entry for this field
        **$old =~ s/\b(\w)/\u$1/g;**
        $self->{'::std_case'}{$field} = $old;
    }
    }

參考: https://github.com/libwww-perl/HTTP-Message/blob/master/lib/HTTP/Headers.pm

':x-inf-route-key'=>'GetID'

謝謝:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM