【发布时间】:2015-06-26 05:55:08
【问题描述】:
我已经用 fcgi 和 C 编写了一个服务器,在我将一些字符串打印到 request.out 之后,我需要添加一些自定义参数。 要清楚这是我的示例代码:
while (1)
{
rc = FCGX_Accept_r(&request);
if (rc < 0)
break;
FCGX_FPrintF(request.out,
"Content-type: text/html\r\n"
"\r\n");
//the html page content
FCGX_FPrintF(request.out,
"<form method=\"post\" action=\"\">"
"<input type=\"text\" name=\"num\">"
"<input type=\"submit\" value=\"click\" name=\"submit\">"
"</form>"
);
.
.
.
//and somewhere like here I need to add a cookie parameter
FCGX_FPrintF(request.out,
"set-cookie:myParam=myValue\r\n"
"\r\n");
.
.
.
.
FCGX_Finish_r(&request);
}
但这最终会直接打印到页面。我怎样才能把它放在缓冲区的开头?
【问题讨论】:
-
你能不能把它写在
Content-Type之前,让它进入到header blob 中? -
在这个服务器中,我解析一个 HTML 页面或一个 CSP 页面,在页面的任何地方都可以调用 Session_start。将一些字符串放入 request.out 流后,如何设置 sessionid。我可以将页面内容放在一个字符串中,然后调用 FCGX_Print(...) 但我正在寻找更好的解决方案。