Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

User-Agent

by Anonymous Monk
on Mar 27, 2003 at 02:31 UTC ( #246146=perlquestion: print w/replies, xml ) Need Help??

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

Hello monks
Basically i have created a socket of the type
#!/usr/bin/perl use IO::Socket; $sock = new IO::Socket::INET ( PeerAddr => 'www.yahoo.com', PeerPort => 80, Proto => 'tcp', Timeout => 10, ); die "Socket could not be created $!\n" unless $sock; print $sock "GET /page?pg=somewhere.html HTTP /1.0\nUser-Agent: Mozil +la/4.0 (compatible; MSIE 5.01; Windows 98; ocnie5-1)\nContent-Type: t +ext/html; charset=EUC-JP\n\n"; while($line = <$sock>) { print "$line\n"; } exit 0;
I have used yahoo just for ex sake. When i give the
User-Agent header and check the log files, i am not getting it
. The user agent is getting printed as it is
2 I-1373-067 User-Agent: Mozilla/4.0 (compatible; MSI +E 5.01; Windows 98; ocnie5-1)
I suppose there is some thing wrong with the format of User-Agent.
Can anyone help me
Thanks in advance

Replies are listed 'Best First'.
Re: User-Agent
by pg (Canon) on Mar 27, 2003 at 03:08 UTC
    Just remove one blank, your code now works. In between 'HTTP' and '/1.0', there should be no space, i.e. it should be 'HTTP/1.0'.

    use IO::Socket; $sock = new IO::Socket::INET ( PeerAddr => 'www.yahoo.com', PeerPort => 80, Proto => 'tcp', Timeout => 10, ); die "Socket could not be created $!\n" unless $sock; print $sock "GET /page?pg=somewhere.html HTTP/1.0\nUser-Agent: Mozill +a/4.0 (compatible; MSIE 5.01; Windows 98; ocnie5-1)\nContent-Type: te +xt/html; charset=EUC-JP\n\n"; while($line = <$sock>) { print "$line\n"; } exit 0;
    Now yahoo no longer complains about received a bad request.

    Of course, because the page you requested does not exist on yahoo, yahoo would reply and say that the page you requested didn't exist, but your request is now well formated.

Re: User-Agent
by blokhead (Monsignor) on Mar 27, 2003 at 02:39 UTC
    1. use LWP; You won't have to learn the intricacies of HTTP conversations.
    2. I fail to see what's wrong with the user agent string you are getting in the log files. It's exactly the same string you passed to the HTTP server. Or am I missing something? Is that example line not from your log files?

    blokhead

      It is a cut and paste from the Log files.
      As i said even i am not able to understand what is wrong.
      It is an old program which i have to change and hence cant use LWP modules.
      Thanks

        If you're changing it, why not make it better?

        Use LWP. It will make things much more easier for you, as well as pave the way for greater functionality, if you desire.

        John J Reiser
        newrisedesigns.com

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://246146]
Approved by diotalevi
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2019-11-18 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (90 votes). Check out past polls.

    Notices?