Teo81 wrote:
Hi. I need to send an HTTP post specifying password and username to a
web server through a socket in order to login. I'm writing this
program in c under a linux system. How does the request has to be
formatted? I send the request using the following code:
write( socket_fd, buffer, strlen( buffer ));
where socket_fd is the socket descriptor, buffer is the string
containing the post request and strlen(buffer) its length.
thank you
As previously stated by Michael Mair this is not the correct place to
ask this question, however I am unaware of the correct newsgroup to
direct you to.
Since by chance I have previously done what you are attempting to do,
here is my two cents. If you need any additional information either find
the relevant newsgroup or try searching google for "http 1.1 rfc" (or
http 1.0 depending on your needs):
<OT>
Authorization is the http header you are needing. The format is as follows:
Authorization: cxHvb57
In the above example, Authorization is the header you need to send, : is
the delimiter used to separate the header name from the value, and
cxHvb57 is a base64 encoded string in the form "username:password". For
example (in pseudo-code) :
size_t http_base64_encode(char *username, char *password, char *tmp)
{
sprintf(tmp, "%s:%s", username, password);
/* do your encoding on tmp here */
return(strlen(tmp));
}
int main(void)
{
char temp[1024];
char stub[200];
http_base64_encode("foo", "bar", stub);
sprintf(temp, "Authorization: %s", stub);
write(socket_fd, temp, strlen(temp));
}
</OT>