当我将表单数据发布到我的服务器时,我的 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,但这对于 POST 来说是不正常的。
关于无法从代理获取 QUERY_STRING 到应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38131561/