Why does my REST request return garbage data?
Posted
by Alienfluid
on Stack Overflow
See other posts from Stack Overflow
or by Alienfluid
Published on 2010-05-26T15:30:03Z
Indexed on
2010/05/27
3:31 UTC
Read the original article
Hit count: 482
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
© Stack Overflow or respective owner