如何将GET和POST数据传递给php可执行文件? [英] How to pass GET and POST data to the php executable?

查看:89
本文介绍了如何将GET和POST数据传递给php可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#编写一个Web服务器,我正在尝试添加对PHP的支持。我主要工作,除了我不知道如何将GET和POST数据传递给PHP可执行文件时,我将文件传递给它。我一直在使用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.

更多关于CGI环境变量的信息(您可以在 http://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可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆