我正在用 C# 编写一个 Web 服务器,并且我正在尝试添加对 PHP 的支持.我大部分时间都在工作,除了我不知道如何在将文件传递给 PHP 可执行文件时将 GET 和 POST 数据传递给它.我一直在使用 GET 进行测试,因为我还没有在服务器上处理 POST 请求,并且我将传递的参数字符串分开,但我不知道如何将信息提供给 php 解析器.一些提示将不胜感激.
I am writing a web server in C# and I'm trying to add support for PHP. I have it mostly working, except I don't know how to past GET and POST data to the PHP executable when i pass the file to it. I've been testing with GET since I haven't gotten to getting POST requests handled on the server, and I have the string of the arguments that gets passed separated, but I don't know how to feed the information to the php parser. Some tips would be appreciated.
对于 GET:简单的方法(我找到了):
For GET: The Easy Way (That i've found):
php-cgi.exe <script-file-name> <parameter1>=<value1> <parameter2>=<value2> [...] <parameterN>=<valueN>
更难的方法(通过 php-cgi 和 windows cli)是:
The Harder Way (via php-cgi and windows cli) would be:
SET "QUERY_STRING=<parameter1>=<value1>&<parameter2>=<value2>&[...]&<paramterN>=<valueN>"
SET SCRIPT_NAME=<script-file-name>
SET REQUEST_METHOD=GET
SET REDIRECT_STATUS=0
php-cgi.exe
我假设有一种方法可以通过 C#/.Net 设置环境变量.php-cgi.exe 完成后,必须取消设置环境变量.
I'd assume there would be a way to set environment variable via C#/.Net. The environment variables would have to be unset after php-cgi.exe completes.
有关您可以在 http://上设置的 CGI 环境变量(以及一般的 CGI)的更多信息www.ietf.org/rfc/rfc3875.txt.PHP 的 $_SERVER 变量文档也可能有用.php.net 上的 PHP 文档中也有将 PHP 作为 CGI 运行的安全注意事项.
More info for CGI environment variables you could set (and CGI in general) at http://www.ietf.org/rfc/rfc3875.txt. Might also be of use would be PHP's $_SERVER variable documentation. Security considerations for running PHP as CGI also in PHP documentation at php.net.
这篇关于如何将 GET 和 POST 数据传递给 php 可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!