If this were Java, we'd skip this step
--#--
Next, we'll need a way to build the request header.
Remember, Pete.java just printed a few strings. But this
is C, so we'll have to devote some time to getting everything
ready to go. At the top of a new file, let's put the server
action we're going to call, and all the parameters. That
way, we can change them more easily.
(Better yet, put them in a text config file and read them in
on program start-up. That way you don't need to re-compile. But
that's an exercise I'll leave to you.)
#include
const char *action = "/darkspell/cgi-bin/secure.cgi";
char *params[] = {
"name=John Byrd",
"game=Java One",
"job=Java Two and Three",
"monkey=Perl",
"what=this and that"
};
We'll also be sending at least three header lines in every request,
so we'll define part of one and all of two of them in one string:
const char *headerStuff = "HTTP/1.0\r\nContent-type: application/x-www-form-urlencode\r\nContent-length: ";
Note that lines are delimited by "\r\n". This is according to Internet RFC
1945, which defines the HTTP protocol.
There's no reason you can't stuff other header lines in here if
you want, User-agent, for instance.