[英]Need help codeigniter restclient with node server
I have a rest client in codeigniter and a server side in node. 我在codeigniter中有一个休息客户端,在节点中有一个服务器端。 The source link for codeigniter rest client My client side rest controller looks like this
Codeigniter Rest Client的源链接我的客户端Rest控制器如下所示
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->spark('restclient/2.1.0');
$this->load->library('rest');
$this->rest->initialize(array('server' => 'http://localhost:3000/'));
}
public function post() {
$param = array(
'var1'=>1,
'var2'=>2
);
$this->rest->format("application/json");
$this->rest->post("/", $param);
var_dump($this->rest->get("/"));
}
}
And on the server side I have 在服务器端,我有
var express = require('express');
var bodyParser = require("body-parser");
var app = express();
var port = 3000;
app.use(bodyParser.urlencoded({ extended: false }));
app.post("/", function (req, res) {
var query1 = req.body.var1;
var query2 = req.body.var2;
res.json({result: parseInt(query1) + parseInt(query2)});
});
app.listen(port);
but when I am requestion localhost/welcome/post
I am getting the resposne 但是当我请求
localhost/welcome/post
我得到了resposne
string(14) "Cannot GET // "
Where am I going wrong? 我要去哪里错了?
change the post function in the CI controller to 将CI控制器中的发布功能更改为
public function post() {
$param = array(
'var1'=>1,
'var2'=>2
);
$this->rest->format("application/json");
//since the server url is allready mentioned as http://localhost:3000/
// no need to mentin "/" again
// response should be handled by a variable
$response = $this->rest->post("", $param);
var_dump($response);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.