我正在尝试将 POST 数据发送到 test.php 文件,该文件仅在提供特定 GET 数据时才处理 POST 数据。不幸的是,我不知道该怎么做;并且已经搜索了大约一个小时。
任何帮助将不胜感激,因为我目前正在玩很多这些神奇的东西。
提前致谢;
一些澄清:
假设您有一个如下所示的 index.php:
<?php
if (isset($_GET['p']))
echo count($_POST) . ' -- ' . count($_GET);
else echo 'fuuu';
?>
<form action="?p" method="POST">
<input type="submit" name="lolw" value="Go" />
</form>
如果您提交该表单,PHP$_GET
和$_POST
superglobals 都将包含 1 个元素。
现在,让我们尝试通过 nodeJS 运行该表单。
这是我的测试用例(这只是从 doku 中的一些剪切粘贴):
var http = require('http');
var options = {
hostname: 'localhost',
port: 80,
path: '/test.php?lolw=1&p',
method: 'POST'
};
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
}).on('error', function (e) {
console.log('error in chunk');
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.toString());
});
// write data to request body
req.write('data\n');
req.end();
CLI 输出为正文提供:0 -- 2,然后遵循表单。
我的观点是:是否可以通过 GET 发送一些参数,通过 POST 发送一些参数,并指定哪些需要通过 GET 发送,哪些需要通过 POST 发送?