Re: newbie question, help heeded
Aron Szabo <
aron@...>
2009-08-11 16:12:10 GMT
Hi!
There is a patch that implements post parsing, but was not added yet(?)
Check this out:
http://www.fastcgi.com/archives/fastcgi-developers/2009-March/000200.html
if( !strcmp(request_method, "POST")
&& content_length_i > 0
&& !strcmp(content_type, "application/x-www-form-urlencoded")
) {
buffer = Malloc(content_length_i + 1);
if (buffer) {
while (readed < content_length_i) {
readed += FCGX_GetStr(buffer + readed, 10000, request->in);
};
*(buffer + content_length_i) = 0;
request->postParamsPtr =
GenerateParamFromWebEscapedString(buffer);
free(buffer); buffer = NULL;
if (request->postParamsPtr) request->postp =
request->postParamsPtr->vec;
} else {
return ENOMEM;
};
};
Good luck,
Aron
Eduard Bareev wrote:
> Hi!
> I trying to develop highspeed web-service and i have some questions,
> and also i am not c++ programmer and this is my first cpp project.
>
> I have this following code:
> ---------------------------------------------------------
> #include <string>
> #include "fcgi_stdio.h"
> #include <stdlib.h>
> #include <iostream>
>
> void handle(FCGX_Request request){
> FCGX_FPrintF(request.out, "Content-type:
> text/html\r\n\r\n<TITLE>fastcgi</TITLE>\n<H1>Fastcgi: Hello
> world!</H1>\n");
> }
>
> int main(int argc, char* const argv[] )
> {
> std::string port=":9001";
> int listenQueueBacklog = 400;
> FCGX_Stream *in, *out, *err;
> FCGX_ParamArray envp;
>
> if(FCGX_Init()) exit(1);
>
> int listen_socket = FCGX_OpenSocket(port.c_str(),
> listenQueueBacklog);
> if(listen_socket < 0) exit(1);
>
> FCGX_Request request;
> if(FCGX_InitRequest(&request, listen_socket, 0)) exit(1);
>
> int reqCounter = 0;
> while(FCGX_Accept_r(&request) == 0)
> {
> handle(request);
> reqCounter++;
> FCGX_FPrintF(request.out, "\n\r\n\r counter: %d", reqCounter);
> FCGX_Finish_r(&request);
> }
> return 0;
> }
> ---------------------------------------------------------
>
> It works good listening 9001 port and serving resquests from nginx
> http server. I choose fcgi_stdio beacuse it can listen on tcp socket
> and it is more simple to integrate all this stuff with nginx web server.
>
> But how can i read post fields?
> Anyone, please point to an example of accessing and parsing post data,
> setting cookies, and other web stuff! I can't find any tutorials or
> examples on the internet!
>
> Thanks!
>
> --
> Eduard Bareev
> eduard@... <mailto:eduard@...>
> ------------------------------------------------------------------------
>
> _______________________________________________
> FastCGI-developers mailing list
> FastCGI-developers@...
> http://mailman.pins.net/mailman/listinfo.cgi/fastcgi-developers
>