Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I have this code that has been working for a while, and someone did something to it and it spotted working. I finally figured it out why, but I just need a better explanation why when a extra line is added to this it will just not respond.
The first part doesn't work, notice the extra line at be beginning of it:
print $sock <<EOM; GET $query HTTP/1.1 Host: quote.yahoo.com Accept: */* User-Agent: quote2.pl EOM

This part works because is hasn't any extra line in it.
print $sock <<EOM; GET $query HTTP/1.1 Host: quote.yahoo.com Accept: */* User-Agent: quote2.pl EOM

Thanks for the explanation!

20050317 Edit by castaway: Changed title from 'Code Question'

Replies are listed 'Best First'.
Re: HTTP Header not working
by brian_d_foy (Abbot) on Mar 15, 2005 at 17:42 UTC

    It looks like you are sending an HTTP request. In an HTTP request, the header is separated by the body by a blank line. In the broken version, it starts with a blank line, and I'm betting the web server chokes (correctly) on that. The first line has to be the request line (that has the GET stuff in it).

    LWP, or at least HTTP::Request can handle this for you.

    --
    brian d foy <bdfoy@cpan.org>
Re: HTTP Header not working
by ikegami (Patriarch) on Mar 15, 2005 at 17:48 UTC
    Quite simply, the HTTP spec dictates the request must start with the request-line (e.g. "GET ..."), not a blank line. Why don't you use LWP instead of (incorrectly) reinventing the wheel?
Re: HTTP Header not working
by Mugatu (Monk) on Mar 15, 2005 at 17:04 UTC
    It is a sign that you should be using LWP. There's even LWP::Simple, which is so easy to use that it makes me cry tears of joy. Or perhaps it is a sign to read the HTTP protocol specs. I like the first option better, though.
Re: HTTP Header not working
by holli (Abbot) on Mar 15, 2005 at 17:01 UTC
    Syntactically there is nothing wrong with both versions. Can you tell what does not work?


    holli, /regexed monk/
A reply falls below the community's threshold of quality. You may see it by logging in.