I am posting again for a problem I didn't quite get an answer to. I seem to have upset someone on this board since I guess I myself am not entirely sure how to define the unexpected output I am experiencing and our discussions spun into many directions. I know this is Perl-specific, this much I know. Here is the GENERAL overview of what I am trying to do:
OVERVIEW
1) C program calls a Perl script with "popen"
2) Said Perl script sends an HTTP GET request to a webserver
3) Webserver returns a plain text file to Perl script
,br>
4) Perl script prints contents returned from webserver, to STDOUT
5) Calling C program captures the output from STDOUT
THINGS I DO KNOW:
a) The webserver is functioning properly and I have explicitly encoded the content to be "text/plain". I have confirmed this by printing out the response header in Perl
b) The C program is properly calling the script. I tested this with a simple print command from within the Perl script; When I call the C program, it is able to capture the print command output from the script (e.g. if I issue "print $var" from Perl, I am able to get that INTO my C program).
PROBLEM
My C program cannot capture the output from my Perl script WHEN I am using an HTTP GET request. In other words, if I put the following lines in my Perl script:
my $variable = "Hello";
print $variable;
My C program will capture "Hello" and print it out if I want. But if I use the following lines, assuming I set the contents returned to "Hello" from the webserver:
my $ua = new LWP::UserAgent;
my $response = $ua->get('http://SOMEURL');
my $decodedContent = $response->decoded_content(charset=>'none');
print $decodedContent;
It prints nothing/blank. I confirmed this by even doing the following:
my $ua = new LWP::UserAgent;
my $response = $ua->get('http://SOMEURL');
my $decodedContent = $response->decoded_content(charset=>'none');
print "HELLO-$decodedContent-HELLO";
....and I my C program prints out "HELLO--HELLO" with nothing in between as HAS BEEN CODED. I tried printing out the above $decodedContent variable to a file. With that I see it, except it obviously is encoded UTF16BE because of the "@^H@^e@^l@^l@^l@^o" characters I see. I don't get this if I print a regular string variable that I created, to file.
I am assuming this is some kind of character encoding problem. HELP!!!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.