Hello all. Consider the following code:
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $ip = 'xxx.xxx.xxx.xxx'; # but with actual real numbers obviously my $port = '82'; # ie not port 80 my $domain_name = 'www.example.com'; my $ua = LWP::UserAgent->new; my $target = "http://$ip:$port/"; $ua->default_header('Host' => $domain_name); my $response = $ua->get($target); print "Response: ".$response->decoded_content."\n";
The 'Host' header is there so the destination server knows which website I'm after on that ip and port. Surely this header should not have any effect on where LWP sends the request? However, I'm getting this:
Response: 500 Can't connect to www.example.com:82It seems to be taking the Host header, adding the port and going to look for that, instead of looking for what is passed to it in $target. Very odd!
If I remove the line that adds the default_header, then:
Response: 200 OKStumped! Can anyone shed any light?
In reply to Adding a 'Host' request header leads to unexpected LWP::UserAgent behaviour by tomgracey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |