By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

socket

P: n/a
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

Sep 23 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Teo81 schrieb:
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.
comp.lang.c is not the right place for this question[*]; I'd try
comp.unix.programmer.
Cheers
Michael
[*] Have a look at http://clc-wiki.net 's introduction to
comp.lang.c
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 23 '06 #2

P: n/a
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>
Sep 24 '06 #3

P: n/a

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
Read HTTP protocol RFC.

The post data would be in the HTTP protocol data part. So you need to
send the HTTP header first then the data.

POST /login.cgi http/1.1\r\n
\r\n\r\n
username=user&password=pass

ps. each line in protocol headers ends with CRLF and protocol headers
end with two CRLF

for quick understanding
http://www.jmarshall.com/easy/http/
http://en.wikipedia.org/wiki/HTTP

-kondal

Sep 24 '06 #4

P: n/a
On Sat, 23 Sep 2006 20:56:21 -0500, in comp.lang.c , Joe Estock
<je*****@NOSPAMnutextonline.comwrote:
>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.
A unix programming one.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 24 '06 #5

P: n/a
Mark McIntyre wrote:
On Sat, 23 Sep 2006 20:56:21 -0500, in comp.lang.c , Joe Estock
<je*****@NOSPAMnutextonline.comwrote:
>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.

A unix programming one.
I'm not so sure this is a unix-specific question. The OP seems to
understand the code and the logic just fine, hence my response. If
anything this was more of a protocol issue.
Sep 26 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.