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!

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to