Your URL parameters are not being url encoded as required. Use a Mojo::URL
instead:
my $url =
Mojo::URL->new('http://klishe.ru/wp-json/posts')->query('filter[post_status]'
=> 'publish', ...);
On Wed, Jul 15, 2015 at 7:35 AM, Pavel Serikov <[email protected]>
wrote:
> Hi guys,
>
> Here is a description of new problem which I don't understand how to
> solve.
>
> I need to use Mojo::UserAgent to parse data from Wordpress site via WP-API
> <http://wp-api.org/>.
>
> If I use browser (just to verify that API url works correctly) - it works.
>
> E.g. this url
> http://klishe.ru/wp-json/posts?filter[post_status]=publish&filter[category_name]=производители&filter[posts_per_page]=-1&filter[nopaging]=true&filter[order]=ASC
> must return 446 json objects.
>
> Checked it with javascript:
> var obj = JSON.parse(document.body.textContent);
> console.log(obj.length);
>
> But if I use Mojo::UserAgent for getting data from same url - it returns
> nothing.
>
> Below is my Mojo script:
>
> #!/usr/bin/env perl
>
> use common::sense;
> use Mojo::UserAgent;
> use feature 'say';
>
> my $ua = Mojo::UserAgent->new;
> #$ua->connect_timeout(0);
> #$ua->request_timeout(0);
> my $url = '
> http://klishe.ru/wp-json/posts?filter[post_status]=publish&filter[category_name]=производители&filter[posts_per_page]=-1&filter[nopaging]=true&filter[order]=ASC
> ';
> my $companies = $ua->get($url)->res->json;
> say scalar @$companies;
>
> If I modify API url to limit numbers of returned objects (from
> filter[posts_per_page]=*-1* to filter[posts_per_page]=*150* ) everything
> works fine.
>
> I suppose that I need to increase some timeouts, but have no idea what
> exact. I tried to set different connect_timeout
> <https://metacpan.org/pod/Mojo::UserAgent#connect_timeout> and
> request_timeout <https://metacpan.org/pod/Mojo::UserAgent#request_timeout>,
> but even with unlimited timeouts it doesn't give any result. Also checked
> values of MOJO_CONNECT_TIMEOUT, MOJO_REQUEST_TIMEOUT and
> MOJO_INACTIVITY_TIMEOUT system variables, it isn't set.
>
> My Mojo is latest stable version, 6.14.
>
> Any suggestion is much appreciated.
>
> --
> 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.
>
--
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.