rfg has asked for the wisdom of the Perl Monks concerning the following question:
Assuming that I am correct that some web servers really do demand this form (in at least some cases), please consider the following simple Perl code:GET abspath Host: hostname
When the above is executed with a full URL as the single command line argument, for example#!/usr/local/bin/perl -w use strict; use HTTP::Request; use LWP::UserAgent; my $orig_url = shift @ARGV; my ($host, $tail); if ($orig_url =~ m%^http://([^/]+)(.*)%) { ($host, $tail) = ($1, $2); } else { die ("Invalid URL: $orig_url\n"); } my $http_request = HTTP::Request->new('GET', $tail, [ 'Host', $host ]) +; $http_request->protocol('HTTP/1.1'); print $http_request->as_string; my $ua = LWP::UserAgent->new (); my $http_response = $ua->request ($http_request); my $http_response_code = $http_response->code; print "HTTP response code: $http_response_code\n"; print $http_response->decoded_content;
The results is as follows:http://www.tristatelogic.com/index.html
I could be wrong, but my impression after having attempted to research this, is that the LWP::UserAgent->request method is being rather entirely unhelpful and unfriendly here, i.e. by refusing to get what it needs... in particular the host name to which the request must be sent... out of the Host: header, rather than out of the GET request line itself.GET /index.html HTTP/1.1 Host: www.tristatelogic.com HTTP response code: 400 400 URL must be absolute
Would you all say that I am correct that, at the very least, this could be characterized as a "non-feature" of the LWP::UserAgent->request method? (I hesitate to call it a bug, even though, at the moment, it does feel like one to me.)
P.S. At the moment, the only work-around for this issue/problem appears to be for the user (i.e. me) to get down and manually use socket programming to send the request to the server in the exact form I need it to be in. If I am missing some other solution, please edify me. Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LWP::UserAgent non-feature?
by Corion (Patriarch) on Jan 13, 2015 at 08:38 UTC | |
|
Re: LWP::UserAgent non-feature? (docs)
by tye (Sage) on Jan 13, 2015 at 15:40 UTC | |
by rfg (Initiate) on Jan 13, 2015 at 19:11 UTC | |
by Anonymous Monk on Jan 13, 2015 at 23:39 UTC | |
|
Re: LWP::UserAgent non-feature?
by Anonymous Monk on Jan 13, 2015 at 08:41 UTC |