Error on ‘user agent (ua)’ get.

32 views
Skip to first unread message

Renato Forti

unread,
Apr 19, 2014, 9:28:35 AM4/19/14
to mojol...@googlegroups.com


Hi All,

I have one error in consume a json that I can’t figure why it occur!

First my service:

https://54.207.83.222/dokcloud-api/1.0/json/test

Note that the cert (https) is self-signed (test server)

The result of this service is a flowing json:

{

    "success": "true",

    "wtm": "0.000000 sec CPU, 0.001368 sec wall",

    "id": "022deedb-13a9-4efc-95a7-6f501464bcf3",

    "test": "true",

    "message": "this is a test/isto é um teste",

    "code": "0"

}

The response header:

HTTP/1.1 200 OK
Date: Sat, 19 Apr 2014 13:23:12 GMT
Server: Apache/2.2.22 (Ubuntu)
Hades Apache Mod: 1.0
Content-Length: 175
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8

You can validate it on http://jsonlint.com/. It is TRUE!

In my mojolicius server I try to consume it like:

package Dokcloud::Test;
 
use Mojo::Base 'Mojolicious::Controller';
use Mojo::UserAgent;
use Mojo::URL;
 
# This action will render a template
sub ts {
 
   my $self = shift;
   my $url = $self->req->url->to_abs;
 
   my $addr = "https://" . $url->host . "/dokcloud-api/1.0/json/test";
 
   my $tx = $self->ua->get($addr);  
 
   if($tx->success)
   {
      if($tx->res->json->{cd} eq '1')
      {
         $self->render(text => "work", format => 'txt' );
      }
   }
}
 
1;

 

https://54.207.83.222/cloud/test

the error:

Can't use an undefined value as a HASH reference at /hades/htdocs/zones/sa/east/1a/dokcloud/script/../lib/Dokcloud/Test.pm line 25.

Why?

If I dump body, the var is empty!

print Dumper(\$tx->res->body); 

$VAR1 = \'';

Thanks for help!

sri

unread,
Apr 19, 2014, 10:15:42 AM4/19/14
to mojol...@googlegroups.com

Hades Apache Mod: 1.0


I believe this header name is invalid, although Chrome seems to accept it, so i've made some adjustments.


--
sebastian

Renato Forti

unread,
Apr 19, 2014, 11:11:49 AM4/19/14
to mojol...@googlegroups.com
Nice! Thanks a lot! Mojolicius is the BEST! How I can update this on my server?
Reply all
Reply to author
Forward
0 new messages