Find the answer to your Linux question:
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 27
If I want to get what a user has typed into a form on a webpage (not clicking "Submit", just typed), in a *C* program, NOT PHP etc., what must ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Mar 2013
    Posts
    354

    How do I get hold of form data on the server side *RAW*?


    If I want to get what a user has typed into a form on a webpage (not clicking "Submit", just typed), in a *C* program, NOT PHP etc., what must I do? ... and please don't just say "use this library", I want to know what's actually going on in AJAX.

    Thanks.

  2. #2
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    943
    Until they hit submit it's all client side and not on the server.
    A lion does not lose sleep, over the opinion of sheep.

  3. #3
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,305
    Your question is really many questions in one. Before a server can receive any data it must be sent so the only way it will have knowledge of what is being sent is if it is submitted.That could happen with every keystroke if a javascript onkeystroke handler is set and each key is being submitted but it would be a silly thing to do.

    When you say in a C program do you mean a web server written in C or a CGI program running in a webserver? The first case you need to study UNIX system and network programming to have any kind of meaningful discussion of. On the other hand a CGI (Common Gateway Interface) program is quite simple to write in any language. In C the users input will be in either the environment variables in the case of a GET or stdin in the case of a POST. In both cases the input will be URL encoded. C has a function, getenv, that can be used to retrieve the QUERY_STRING from the environment.

    There is a global variable, environ (char** environ), available to your C program and the CGI server puts information such as headers in that variable.

  4. #4
    Linux User
    Join Date
    Mar 2013
    Posts
    354
    I meant a CGI program, thanks. Btw, what's the exact difference between GET and POST? If both of them are URL-encoding it??? Why did they make 2 of them?

    So even if the .js onkeystroke thing is used, it's still calling an Executable on the server saying "key p has been pressed", and the server then replies, did I get that right?

  5. #5
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    943
    Javascript is mainly client/browser protocal so the keystokes are only known to the browser until submitted to the server. There is server side javascript these days called node.js.

    If you interested in the interaction between your client/browser and the web server you should run wireshark or any TCP/IP packet capture tool and filter down only your browser. Then you can see all the packets and the contents of the packets.
    A lion does not lose sleep, over the opinion of sheep.

  6. #6
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,305
    Quote Originally Posted by resetreset View Post
    I meant a CGI program, thanks. Btw, what's the exact difference between GET and POST? If both of them are URL-encoding it??? Why did they make 2 of them?

    So even if the .js onkeystroke thing is used, it's still calling an Executable on the server saying "key p has been pressed", and the server then replies, did I get that right?
    Sort of. The server that hosts the CGI calls the executable when the request comes in and it makes available a standardized set of data elements. It's up to your program to decide what has occurred based on the data.

    The HTTP specification makes available a variety of actions called methods: GET, POST, PUT, DELETE, HEAD, TRACE, CONNECT and OPTIONS. They each have a role but the last four are handled by the server generally.The first four can be passed to a web application to respond to. There are limitations on the length of a url and the data that can be passed that way so larger data sets are handled in the body of a request instead of the URL.

  7. #7
    Linux User
    Join Date
    Mar 2013
    Posts
    354
    Quote Originally Posted by gregm View Post
    Sort of. The server that hosts the CGI calls the executable when the request comes in and it makes available a standardized set of data elements. It's up to your program to decide what has occurred based on the data.

    The HTTP specification makes available a variety of actions called methods: GET, POST, PUT, DELETE, HEAD, TRACE, CONNECT and OPTIONS. They each have a role but the last four are handled by the server generally.The first four can be passed to a web application to respond to. There are limitations on the length of a url and the data that can be passed that way so larger data sets are handled in the body of a request instead of the URL.

    ....so Apache sets some environment variables and then runs a CGI program...?



    ...and larger data sets are handled in the body of *what kind of* request?



    Does AJAX use these methods? Or have they invented something separate for it?

  8. #8
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,305
    Quote Originally Posted by resetreset View Post
    ....so Apache sets some environment variables and then runs a CGI program...?



    ...and larger data sets are handled in the body of *what kind of* request?



    Does AJAX use these methods? Or have they invented something separate for it?
    Yes, Apache sets the environment and runs the CGI program.

    AJAX uses GET, POST, PUT, or DELETE. Usually the body of a request is only used with POST and PUT. It may work with a GET and DELETE but I wouldn't count on it.

  9. #9
    Linux User
    Join Date
    Mar 2013
    Posts
    354
    ...so for transmitting the fact that "key p has been pressed", would AJAX use GET or POST or PUT? (what's PUT exactly? GET and POST I've heard of, what does PUT do?)


    thanks for your help.

  10. #10
    Linux Engineer
    Join Date
    Dec 2013
    Posts
    1,305
    None of them do anything - but they are specified in a way to allow for interoperation of web programs. Hypertext Transfer Protocol -- HTTP/1.1

    Which you use will depend on your reading of the document in the link and what it triggers. If what you're doing is returning a specific document based on the key pressed then it's a GET.

Page 1 of 3 1 2 3 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •