Hi,
Got this annoying thing I've been battling with for the last hour or so :(
Basically - the user account can provide a URL in the format of http://user:pass@domain.com/file.csv, OR just http://domain.com/file.csv.
The code below checks to see if there is an @ in the URL, and if so it will try and use the authorization_basic() function of HTTP::Request.
It works perfectly when not trying to do user:pass , but when you include a password in the URL it doesn't work. Here is the code:
my $url_to_get = $_[1] || $details->{client_detail_url_list_offers
+};
my $ua = LWP::UserAgent->new;
$ua->agent("Import Script for VoyageForum");
$ua->timeout(10);
#$ua->env_proxy;
# if we have an @ in the URL, they will be giving us something lik
+e ftp://someone:somewhere@doamin.com .. so we need to process this ap
+propriatly..
my $request;
if ($url_to_get =~ /\@/) {
my @split = split /\@/, $url_to_get; # [ftp://user:pass] @ [do
+main.com]
# ok, lets try and get the bit after //, so we have the user/p
+ass combo...
if ($split[0] =~ m|(.*)//(.*)|) {
print $IN->header;
#print qq|Got user/pass combo of: $2 \n|;
my ($user,$pass) = split /\:/, $2;
$request = HTTP::Request->new(GET => qq|$1/$split[1]|);
$request->authorization_basic($user, $pass);
print qq|Bla, got URL of: "$1//$split[1]" <br />user: $use
+r <br />pass: $pass <br /><br />|;
#exit;
}
} else {
$request = HTTP::Request->new(GET => $url_to_get);
}
my $response = $ua->request($request);
..and I get this error:
Bla, got URL of: "http://domain.org/illicotravel_import/marmara.txt"
user: dev
pass: password
(which is all exactly right)... yet I get this error:
Error: 500 No Host option provided
Anyone got any ideas? I'm coming up blank here :(
TIA!
Andy
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.