1 回答
TA贡献1804条经验 获得超2个赞
我找到了一个答案,我们必须将POST方法更改为GET方法。
更新的控制器代码:
$_POST = json_decode(file_get_contents('php://input'), true);
echo "<pre>"; print_r($_GET);
更新节点 js 代码:
var request = require('request');
var http = require('http');
var post_body = {
pos1: '10',
pos2: '15'
};
var post_body_json = JSON.stringify(post_body);
var post_options = {
host: 'localhost',
path: '/govtech/pab/branches/testing/index.php/websocket/node_data',
body: post_body_json,
method: 'GET',
headers: {
'User-Agent': 'Super Agent/0.0.1',
'Content-Type': 'application/x-www-form-urlencoded',
}
};
var post_req = http.request(post_options, function (res) {
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
post_req.end();
- 1 回答
- 0 关注
- 148 浏览
添加回答
举报