I am trying to use LWP::UserAgent to get data from a simple web server I have created on an Arduino.
The request succeeds, but the decoded_content contains all of the response header. The information contained in the headers_as_string value is not sent from the server. The server sends "\r\n" for all line endings and an blank line with "\r\n" to mark the end of the header.
I have tried adding various attributes to the response header, but all had the same result of the header being in the decoded_content value.
Any thoughts on what may be causing the headers to be included in the content?
Thanks
Perl codeOutput from above code#!/opt/local/bin/perl use LWP::UserAgent; use JSON; use warnings; use strict; my $ua = LWP::UserAgent->new; my $server_endpoint = "http://192.168.0.198/LED1"; my $req = HTTP::Request->new( GET => $server_endpoint ); $req->header('content-type' => 'application/json'); my $resp = $ua->request($req); if ( $resp->is_success ) { my $header = $resp->headers_as_string; print "Received header:\n$header\n---------\n"; my $message = $resp->decoded_content; print "Received reply:\n$message\n---------\n"; } else { print "HTTP GET error code: ", $resp->code, "\n"; print "HTTP GET error message: ", $resp->message, "\n"; }
Received header: Client-Date: Mon, 17 Mar 2014 22:45:08 GMT Client-Peer: 192.168.0.198:80 Client-Response-Num: 1 --------- Received reply: HTTP/1.1 200 OK Content-Type: application/json Connection: close {"val":1} ---------
In reply to LWP UserAgent response header in decoded_content by jeff_e
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |