|
Home > Archive > Unix Programming > September 2006 > socket
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| 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
| |
| Hubble 2006-09-23, 1:28 pm |
| teo 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.
>
> thank you
A POST request, additional headers, an emtpy line (\r\n) and the
post data.
To authenticate using basic authentication (the most common used), you
have to concatenate username and password with a colon and
base64 encode the result. This has to be included in the headers as
"Authorization Basic ..."
>From RFC 2617:
If the user agent wishes to send the userid "Aladdin" and password
"open sesame", it would use the following header field:
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
(http://ww.faqs.org/rfcs/rfc2617.htm).
So probably
POST /filename HTTP/1.1\r\n
Host: www.example.net\r\n
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n
\r\n
<<post data>>
will do.
However, if you do not really want to learn the details, a better
choice is to call wget or curl from your C-program (via popen(3)).
Hubble.
| |
| Damian 'legion' Szuberski 2006-09-23, 7:29 pm |
| On 2006-09-23, teo 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.
Use libcurl.
--
Damian Szuberski
| |
| jmcgill 2006-09-23, 7:29 pm |
| Damian 'legion' Szuberski wrote:
> Use libcurl.
Do you prefer libcurl to the w3c http libs?
| |
| Damian 'legion' Szuberski 2006-09-23, 7:29 pm |
| On 2006-09-23, jmcgill wrote:
> Do you prefer libcurl to the w3c http libs?
What's the problem?
--
Damian Szuberski
| |
|
| First of all, Thank you for your answer
I only need to log in. The log in informations are base64 encoded in
the header. So, what about the body? It seems to be not necessary to
me. Have I to send an empty body?How? Can I merge body and header in a
unique buffer and send them all together or have I to use 2 different
write?
Hubble wrote:
> teo schrieb:
>
>
> A POST request, additional headers, an emtpy line (\r\n) and the
> post data.
>
> To authenticate using basic authentication (the most common used), you
> have to concatenate username and password with a colon and
> base64 encode the result. This has to be included in the headers as
> "Authorization Basic ..."
>
>
> If the user agent wishes to send the userid "Aladdin" and password
> "open sesame", it would use the following header field:
>
> Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
>
> (http://ww.faqs.org/rfcs/rfc2617.htm).
>
> So probably
>
> POST /filename HTTP/1.1\r\n
> Host: www.example.net\r\n
> Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n
> \r\n
> <<post data>>
>
> will do.
>
> However, if you do not really want to learn the details, a better
> choice is to call wget or curl from your C-program (via popen(3)).
>
> Hubble.
|
|
|
|
|