Re(3): bsd sockets & http
Re(3): bsd sockets & http
- Subject: Re(3): bsd sockets & http
- From: Jens Bauer <email@hidden>
- Date: Sun, 1 Sep 2002 14:58:47 +0200
Hi Jens (that's myself. :)),
I'd like to let anyone know of a bug in a code-snippet I posted.
It's a snippet I found on the net.
After reading the RFCs carefully, I found out that you need to terminate
even GET requests by an empty line.
On Sat, 20 Jul, 2002, Jens Bauer <email@hidden> wrote:
{snip}
>
>
You are right about that. Most servers and clients are able to handle
>
"\n", which can be either CR or LF, however, some clients require
>
"\12\15" (CR followed by LF).
>
>
>Oh, and you don't need the bind(). Better to skip it and have one less
>
>possible error to deal with.
>
>
Now, this is the nice thing about going Unix... Try having a look at this
>
source-code snippet I found on the net:
>
>
<http://hoohoo.ncsa.uiuc.edu/beta-1.6/scripts/src/tmp>
>
>
It's for POSTing a request, which means it's not really a GET, as you
>
want, but you might be able to find out what's causing the trouble by
>
looking at the snippet.
Ofcourse the link is now dead, however we have Google, which will rescue
those of us who didn't grab a copy:
<
http://216.239.37.100/search?q=cache:0wdx0NOQ-6QC:hoohoo.ncsa.uiuc.edu/
beta-1.6/scripts/src/tmp+"web_req"&hl=en&ie=UTF-8>
The last few lines look something like this:
-----------
}
sprintf(buf,"\n\n");
err = write(sock, buf, strlen(buf));
if (err < 0) {
fprintf(stderr, "request end write failed, error #%d\n",err);
close(sock);
return -1;
}
}
while (read(sock,buf,1024) == 1024) ;
-----------
An easy (and clumsy, it's coded clumsy already!) correction would be to
split it into something like this:
-----------
}
sprintf(buf,"\n");
err = write(sock, buf, strlen(buf));
if (err < 0) {
fprintf(stderr, "request end write failed, error #%d\n",err);
close(sock);
return -1;
}
}
sprintf(buf,"\n");
err = write(sock, buf, strlen(buf));
if (err < 0) {
fprintf(stderr, "request end write failed, error #%d\n",err);
close(sock);
return -1;
}
while (read(sock,buf,1024) == 1024) ;
-----------
This way, we *will* get the last empty line if we're not sending a body.
I only used this for POST methods, so I didn't see the error until today,
where I used the same code for a GET method.
Love,
Jens
--
Jens Bauer, Faster Software.
-Let's make the World better, shall we ?
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.