socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Teo81

    #1

    socket

    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

  • Michael Mair

    #2
    Re: socket

    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.progr ammer.


    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.

    Comment

    • Joe Estock

      #3
      Re: socket

      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:passw ord". For
      example (in pseudo-code) :

      size_t http_base64_enc ode(char *username, char *password, char *tmp)
      {
      sprintf(tmp, "%s:%s", username, password);

      /* do your encoding on tmp here */

      return(strlen(t mp));
      }

      int main(void)
      {
      char temp[1024];
      char stub[200];

      http_base64_enc ode("foo", "bar", stub);

      sprintf(temp, "Authorizat ion: %s", stub);

      write(socket_fd , temp, strlen(temp));
      }
      </OT>

      Comment

      • kondal

        #4
        Re: socket


        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&p assword=pass

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

        for quick understanding
        Tutorial: Quickly learn how to use HTTP in your network applications, if you know basic sockets programming. Covers HTTP 1.0 and HTTP 1.1. Includes sample clients in Perl.



        -kondal

        Comment

        • Mark McIntyre

          #5
          Re: socket

          On Sat, 23 Sep 2006 20:56:21 -0500, in comp.lang.c , Joe Estock
          <jestock@NOSPAM nutextonline.co mwrote:
          >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

          Comment

          • Joe Estock

            #6
            Re: socket

            Mark McIntyre wrote:
            On Sat, 23 Sep 2006 20:56:21 -0500, in comp.lang.c , Joe Estock
            <jestock@NOSPAM nutextonline.co mwrote:
            >
            >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.

            Comment

            Working...