无法从代理到应用程序获取 QUERY_STRING

Can't get QUERY_STRING from proxy to application

当我 POST 将数据发送到我的服务器时,我的 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.

在正常的POST中,数据不在QUERY_STRING中,而是通过标准输入传递给CGI进程。看看FCGX_Request.in.

如果你的URL里面有?a=b,你也可以有一个QUERY_STING,但这对[=20来说是不正常的=].