I have a CGI exe application running on IIS. A client (localhost:8080 for testing) can make a request to the server with any application name (e.g. home, store, account, etc...) and any additional queries (e.g. ?test=1&magic=2). Currently, the exe will load and run the code in it but is unable to receive client input via POST or GET.
I have been recommended to try using WT and similar libraries to capture the HTTP and URL information I need, but I'd like to learn to do it without a separate library.
Using C , how do I capture HTTP request data from the client, URL parameters, cookie data, etc.. via client GET and POST then store that data in variables and constants for later use?
CodePudding user response:
A CGI app runs as a separate process. It receives client data on stdin
, and sends data to the client on stdout
. When the webserver receives a client connection, it spawns the CGI process hooking up the connected socket to the stdin
and stdout
handles.
So, for example, if a client requests http://localhost:8080/home?test=1&magic=2
, the CGI's stdin
should receive data similar to this:
GET /home?test=1&magic=2 HTTP/1.1
Host: localhost:8080
Cookie: ...
And then it can write to stdout
, something like this:
HTTP/1.1 200 OK
Content-Type: desired media type
Content-Length: XXXXX
Set-Cookie: ...
data here
CodePudding user response:
Heres a https server u can compile from src https://bitbucket.org/ptroen/crossplatformnetwork/src/master/OSI/Application/Stub/HTTPSServer/httpsserver.cc
I wrote this and performance is pretty good. See http server if u dont care about encryption. You will need to define two flyweight classes in order to initialize with your specific cgi biz logic.
It supports post put get delete. Havent tested with cookies but wont be hard to implement.