Home: Perl Programming Help: Intermediate:
"HTTP::Headers" error on apostrophe in URL



Bucz
Novice

May 2, 2009, 3:32 PM


Views: 8355
"HTTP::Headers" error on apostrophe in URL

Hello,

a strange error I get when trying to invoke LWP UserAgernt:

Can't locate object method "sprint" via package "HTTP::Headers" at /Library/Perl/5.8.8/HTTP/Message.pm line 536.

I just figured out that it occurs when I add an apostrophe to the URL:

this is OK:
$req->content("id=1002")

this is errorous (%27 is an apostrophe ' )
$req->content("id=1002 %27")

I have just updated packages with CPAN so it should go OK. I user the most simple standard code to test UserAgent

I use Mac OS 10.5 if it makes a difference

Any ideas?


(This post was edited by Bucz on May 2, 2009, 4:12 PM)


KevinR
Veteran


May 2, 2009, 4:27 PM


Views: 8350
Re: [Bucz] "HTTP::Headers" error on apostrophe in URL

if you literally need to pass a percent sign try %25:


Code
$req->content('id=1002%20%2527')


note %20 is a space and %25 is the percent symbol.
-------------------------------------------------


Bucz
Novice

May 3, 2009, 3:13 AM


Views: 8344
Re: [KevinR] "HTTP::Headers" error on apostrophe in URL

hi,

i need to pass apostrophe that is %27, so still no clue


FishMonger
Veteran / Moderator

May 3, 2009, 5:37 AM


Views: 8334
Re: [Bucz] "HTTP::Headers" error on apostrophe in URL

Have you tried using single quotes instead of double quotes? The double quotes causes variable interpolation, which in this case you don't want.

change it to:
$req->content('id=1002 %27')

or:
$req->content('id=1002%20%27')


(This post was edited by FishMonger on May 3, 2009, 5:37 AM)


KevinR
Veteran


May 3, 2009, 10:06 AM


Views: 8329
Re: [FishMonger] "HTTP::Headers" error on apostrophe in URL


In Reply To
Have you tried using single quotes instead of double quotes? The double quotes causes variable interpolation, which in this case you don't want.

change it to:
$req->content('id=1002 %27')

or:
$req->content('id=1002%20%27')


There is no variable interpolation in that string though. Only scalars and arrays are converted to strings inside of double-quotes. Using the correct quotes is always a good idea though.
-------------------------------------------------


FishMonger
Veteran / Moderator

May 3, 2009, 10:27 AM


Views: 8328
Re: [KevinR] "HTTP::Headers" error on apostrophe in URL

My bad...I should have done a copy/paste.

The original post had used double quotes which would have caused a problem with %27 because Perl would have attempted to interpolate that as a hash and if running under strictures, that would cause a compilation error. I'll leave it to the reader to determine why it would be a compilation error.


Quote
Can't use global %27 in my at ...


My bad, again.

Yes Kevin, you're right. I forgot that fact.



(This post was edited by FishMonger on May 3, 2009, 10:30 AM)


KevinR
Veteran


May 3, 2009, 10:35 AM


Views: 8325
Re: [FishMonger] "HTTP::Headers" error on apostrophe in URL

Maybe I am miss-understanding something, but hashes inside of quotes, even double-quotes, are not subject to interpolation/expansion:


Code
use strict; 
use warnings;

print "this is a %27 test";


Only scalars, arrays and meta sequences are.
-------------------------------------------------


KevinR
Veteran


May 3, 2009, 10:39 AM


Views: 8323
Re: [Bucz] "HTTP::Headers" error on apostrophe in URL


In Reply To
hi,

i need to pass apostrophe that is %27, so still no clue


then maybe:

$req->content(q{id=1002 '})
-------------------------------------------------