Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to format web service response to be read by Perl?
    primarykey
    data
    text
    <p>I'm using Perl to request some information (plain text) from a web service I built. When accessing using the browser, the info is shown perfectly. However, I'm new to handle responses using Perl. I do some database operations successfully, and my problem comes handling the response in Perl, not PHP.</p> <p>How do I must encode or format the response in order to handle it successfully and output the same plain text in Perl?</p> <p>EDIT:</p> <p>Key points to take into consideration</p> <ul> <li>I'm working with CakePHP 2.x (stable).</li> <li>The <strong><em>$response->content</em></strong> brings the whole HTML file (including JavaScript and the whole package). I just want to show the plain text in the Perl script.</li> <li>The Perl script fails when checking <strong>*$response->is_success*</strong> and goes straight to <strong><em>print "something went wrong";</em></strong>.</li> </ul> <p>My php script runs well</p> <p>PHP code:</p> <pre><code>&lt;?php $this-&gt;layout = 'ajax'; $this-&gt;autoRender = false; // Some database handling here with no problem... echo "Plain text with info from database"; ?&gt; </code></pre> <p>Perl code:</p> <pre><code>#!/usr/local/bin/perl require LWP::UserAgent; require HTTP::Request; my $request = HTTP::Request-&gt;new(GET =&gt; $url); my $userAgent = LWP::UserAgent-&gt;new; $userAgent-&gt;timeout(3); $userAgent-&gt;env_proxy; my $response = $userAgent-&gt;request($request); if ($response-&gt;is_success) { print "Success!\n"; #should print plain text AS IS } else { print "something went wrong...\n"; die $response-&gt;status_line; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload