Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 825255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:13:32+00:00 2026-05-15T03:13:32+00:00

I am trying to use LWP::Simple to make a GET request to a REST

  • 0

I am trying to use LWP::Simple to make a GET request to a REST service. Here’s the simple code:

use LWP::Simple;
$uri = "http://api.stackoverflow.com/0.8/questions/tagged/php";
$jsonresponse= get $uri;
print $jsonresponse;

On my local machine, running Ubuntu 10.4, and Perl version 5.10.1:

farhan@farhan-lnx:~$ perl –version
This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi

I can get the correct response and have it printed on the screen. E.g.:

farhan@farhan-lnx:~$ head -10 output.txt
{
“total”: 1000,
“page”: 1,
“pagesize”: 30,
“questions”: [
{
“tags”: [
“php”,
“arrays”,
“coding-style”
(… snipped …)

But on my host’s machine to which I SSH into, I get garbage printed on the screen for the same exact code. I am assuming it has something to do with the encoding, but the REST service does not return the character set type in the response, so how do I force LWP::Simple to use the correct encoding? Any ideas what may be going on here?

Here’s the version of Perl on my host’s machine:

[dredd]$ perl –version
This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:13:32+00:00Added an answer on May 15, 2026 at 3:13 am

    I happen to have a 64 bit RHEL 5.4 box which has Perl 5.8.8 on it. I took your code and got the exact same result. I tried using Data::Dumper to dump the data, but that didn’t change anything. I then went to the command line and did this:

     wget -O jsonfile http://api.stackoverflow.com/0.8/questions/tagged/php
     --2010-05-26 11:42:41--  http://api.stackoverflow.com/0.8/questions/tagged/php
     Resolving api.stackoverflow.com... 69.59.196.211
     Connecting to api.stackoverflow.com|69.59.196.211|:80... connected.
     HTTP request sent, awaiting response... 200 OK
     Length: 5430 (5.3K) [application/json]
     Saving to: `jsonfile'
     2010-05-26 11:42:42 (56.9 KB/s) - `jsonfile' saved [5430/5430]
    

    When I did this:

     file jsonfile
    

    I got:

    jsonfile: gzip compressed data, from FAT filesystem (MS-DOS, OS/2, NT), max speed
    

    So, the JSON data was gzipped by the web server. I tried this:

    gzip -dc jsonfile
    

    and lo and behold the results are the JSON data as you would expect.

    What you can do now is to either use another module to ungzip the data, or you can check out this other thread which shows how to accept gzip using LWP::UserAgent and handle the request that way

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to use a guid as a resource id in a rest url but
I trying to use ImageInfo and Jython to get information from a image on
I'm trying to use jQuery to format code blocks, specifically to add a <pre>
I'm trying to use the Optiflag package in my Ruby code and whenever I
I'm trying to fetch Wikipedia pages using LWP::Simple , but they're not coming back.
use Parallel::ForkManager; use LWP::Simple; my $pm=new Parallel::ForkManager(10); our $a =0; @LINK=( 10,203, 20, 20
I am trying to get an image from an HTTP server using Perl. I
I'm trying to get Code Closure to work, but unfortunately, there's always an error
Trying to use make from cygwin using g++ I was getting Access Denied error
Trying to use Linq with some Entity objects to do a crafty query here.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.