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

OS: Windows 2000, Perl: ActiveState 5.6.1

Hi,

I'm trying to use IO::Sockets to get a web page. I'm not using LWP::UserAgent, because of Microsoft Proxy/NTLM issues,

http://www.perlmonks.com/index.pl?node_id=271214

I am unable to get the page the connection times out. I'm also running the test code from the proxy to avoid any NTLM issues for the time being.

use IO::Socket; $socket=IO::Socket::INET->new( Proto => 'tcp', PeerAddr => 'www.nai.com', PeerPort => 'http(80)'); print "... $socket\n"; # http://www.nai.com/us/index.asp print $socket "GET /us/index.asp HTTP/1.0"; open (OUT, ">out.txt"); while (<$socket>) { print OUT; } close (OUT); close $socket;

The output I get is...<br><br> HTTP/1.0 408 Request Time-out Server: AkamaiGHost Mime-Version: 1.0 Date: Mon, 07 Jul 2003 14:54:57 GMT Content-Type: text/html Content-Length: 163 Expires: Mon, 07 Jul 2003 14:54:57 GMT <HTML><HEAD> <TITLE>Request Timeout</TITLE> </HEAD><BODY> <H1>Request Timeout</H1> The server timed out while waiting for the browser's request.<P> </BODY></HTML>


Thanks.

Mitch

Replies are listed 'Best First'.
Re: Web Page - IO::Sockets
by gellyfish (Monsignor) on Jul 07, 2003 at 15:24 UTC

    The server will not send a response until it sees the end of the headers which is indicated by a blank line. You should change the line:

    print $socket "GET /us/index.asp HTTP/1.0";
    to
    print $socket "GET /us/index.asp HTTP/1.0\r\n\r\n";
    Hope That helps

    /J\
    
      Thanks for getting back to me.

      The \r\n\r\n did send the request through, but the response comes back as an invalid Url. If I put the path in the browser I am able to get to the page?
      <HTML><HEAD> <TITLE>Invalid URL</TITLE> </HEAD><BODY> <H1>Invalid URL</H1> The requested URL "&#47;us&#47;index&#46;asp", is invalid.<p> </BODY></HTML>


      Mitch