我在php中开发了一个Windows Web服务器,我想使用php-cgi。 它运行良好,但我遇到了GET和POST请求问题。当我设置环境变量" REQUEST_METHOD"到" POST",我在$ _POST变量中没有得到任何东西,但是我在$ _GET中得到了内容:/它没有任何意义......
这是我的代码:
Process php = new Process();
php.StartInfo.FileName = "C:/PHP-7.1/php-cgi.exe";
php.StartInfo.RedirectStandardOutput = true;
php.StartInfo.UseShellExecute = false;
php.StartInfo.EnvironmentVariables["GATEWAY_INTERFACE"] = "CGI/1.1";
php.StartInfo.EnvironmentVariables["SCRIPT_FILENAME"] = page;
php.StartInfo.EnvironmentVariables["REQUEST_METHOD"] = "POST";
php.StartInfo.EnvironmentVariables["REDIRECT_STATUS"] = "true";
php.StartInfo.EnvironmentVariables["SERVER_PROTOCOL"] = "HTTP/1.1";
php.StartInfo.EnvironmentVariables["SERVER_SOFTWARE"] = ServerVersion;
php.StartInfo.EnvironmentVariables["REMOTE_HOST"] = "127.0.0.1";
//php.StartInfo.EnvironmentVariables["CONTENT_LENGTH"] = "3"; // Causes crash
php.StartInfo.EnvironmentVariables["HTTP_ACCEPT"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
php.StartInfo.EnvironmentVariables["CONTENT_TYPE"] = "text/html";
String QueryString = "";
if (request.GET_Variables.Count() > 0)
{
int i = 0;
foreach (String variable in request.GET_Variables)
{
QueryString += variable + "=" + request.GET_Values[i];
i++;
if (i != request.GET_Variables.Count())
{
QueryString += "&";
}
}
}
php.StartInfo.EnvironmentVariables["QUERY_STRING"] = QueryString;
php.StartInfo.Arguments = "-f \"" + page + "\"";
Console.WriteLine("php-cgi.exe " + php.StartInfo.Arguments); // Debug
php.Start();
例如,如果:
QUERY_STRING="fox=brown&dog=lazy"
var_dump();会是这样的:
GET: array(2) { ["fox"]=> string(5) "brown" ["dog"]=> string(4) "lazy" }
POST: array(0) { }
我希望有人可以帮助我,祝你有愉快的一天!