我面临$_POST
在PHP
文件中获取数据的问题。由于我的要求是发送帖子变量。
var rp = require('request-promise');
var options = {
method: 'POST',
uri: 'http://localhost/orangehrm_live/capacity-dashboard/getAllDetailsCapacity.php',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': dataString.length
},
body: {
some: 'payload'
},
json: true // Automatically parses the JSON string in the response
};
rp(options)
.then(function (repos) {
console.log('User has %d repos', repos.length);
if (repos) {
res.send(repos);
} else {
res.sendStatus(404);
}
})
.catch(function (err) {
res.status(400).send(err);
});
我的PHP文件包含以下代码。
<?php
class getAllDetailsCapacity{
public function getChartRawData(){
//$data = array('message' => 'HeLLO');
$json = json_encode($_POST);
print_r($json);
}
}
function node_dispatch() {
$obj=new getAllDetailsCapacity();
if(isset($_POST)) {
$obj->getChartRawData();
}
else {
echo "You are in Admin Mode. Switch back to normal mode to serve your node app.";
}
}
node_dispatch();
?>
它在节点功能的请求承诺正文中显示其他语句,因为它没有获得后值。
$ _POST包含键值对时,将接收该帖子主体。您需要使用要在正文中进行url编码的值来POST到php。
HTTP请求可能如下所示:
POST /path/to/file.php HTTP/1.1
...
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
foo=bar&bar+baz=foo
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句