【发布时间】:2016-11-03 01:09:29
【问题描述】:
当我将表单数据发布到我的服务器时,我的 fastcgi 应用程序能够从 nginx 读取每个参数,但 QUERY_STRING 除外。查看 CONTENT_LENGTH 给出了正确的字符串长度,并且我的浏览器显示正在发送的数据,所以我只能认为没有设置某些内容或者我在寻找错误的地方。
我的位置文件:
location /testpage/test {
include fastcgi_params;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
fastcgi_pass unix:/var/run/fcgi-sock.fcgi;
fastcgi_param SCRIPT_FILENAME /www/test-app;
}
我的测试应用:
#include "/usr/local/include/fcgiapp.h"
int main()
{
FCGX_Request request;
FCGX_Init();
FCGX_InitRequest(&request, 0, 0);
while (FCGX_Accept_r(&request) == 0)
{
FCGX_FPrintF(request.out, "Content-type: text/html\r\n\r\n <h1>Hello World!</h1>");
char* q=FCGX_GetParam("REQUEST_METHOD",request.envp);
if(q) FCGX_FPrintF(request.out, "%s", q);
else FCGX_FPrintF(request.out, "nope");
q=FCGX_GetParam("QUERY_STRING",request.envp);
if(q) FCGX_FPrintF(request.out, "%s", q);
else FCGX_FPrintF(request.out, "nope");
}
我知道我需要解析字符串,但我只想首先获取字符串,正如我所说,我可以打印出 REQUEST_METHOD 和其他几个参数,而不是 QUERY_STRING。
【问题讨论】: