Avatar billede surreal Nybegynder
04. juli 2006 - 14:53

End of stream identifier

Hi there,

I want to be able to read a HTTP request from a socket handle until the end of the request is reached. I want to be able to read GETs and POSTs. In the situation of a POST, I want to read both the header and the payload. Here is an example:

# HEADER
POST /file.pl http://HTTP/1.0
Host: http://www.me.dk
Content-Length: 12
Content-Type: html/text

# PAYLOAD
name=surreal

I can read the request if it is a GET with the current code, as there is no payload to read. I am having troubles with POST requests. Here is some code:

my $firstline = <$client>;
# GET /index.html http://HTTP/1.1
$firstline =~ m/^(\w+)\s+(\S+)(?:\s+(\S+))?\r?$/;
$self->{_METHOD} = $1 || '';
$self->{_RESOURSE} = $2 || '';
$self->{_PROTOCOL} = $3 || '';

my @line = ();
my @temp = ();
while(<$client>) {
  # if End Of Stream then last...
  push(@temp);
  print(pop(@temp));
  @line = split(/:/);
  print($line[0], $line[1]);
}

I am uncertain if the whole read the handle (<$client>) is a clever idea but ultimately, I want some relitively generic code that will both be able to read a GET request as well as a POST with payload (..and eventually a WebDAV and payload).

I look forward to hearing your wise words!
thanks very much in advance.

/S.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester



IT-JOB