Strange HTTP Socket connexion problem

A

axel

I'm having a strange problem trying to connect to a specific site
with an HTTP request. Originally I was trying to send a SOAP request,
but have whittled the script down to the most basic HTTP request
possible:

--- start
#!/usr/bin/perl

use strict;
use warnings;
use Socket;

my $header = <<EOM;
GET / HTTP/1.1
Host: www.webservicex.net

EOM

socket (CLIENT, PF_INET, SOCK_STREAM, getprotobyname('tcp'))
or die "socket: $!\n";
bind (CLIENT, sockaddr_in(0, INADDR_ANY))
or die "bind: $!\n";

my $host = 'www.webservicex.net';
my $rport = 80;
my $ip_addr = inet_aton($host)
or die "inet_aton: $!\n";
my $rsockaddr = sockaddr_in($rport, $ip_addr);
connect(CLIENT, $rsockaddr)
or die "connect: $!\n";

my $ofh = select CLIENT;
$|++;
select $ofh;

print CLIENT $header;

while (<CLIENT>) {
print;
}
__END__

For this particluar site (www.webservicex.net) the result is:

--- start
HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Sun, 16 Oct 2005 16:57:56 GMT
Connection: close
Content-Length: 20

<h1>Bad Request</h1>
--- end

For *every* other site I have tried, it works perfectly. Also
telneting to port 80 using a cut and paste from the $header
defined above actually works - even stranger unless I am
missing something very obvious.

Axel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top