首页 > 解决方案 > 我试图在托管站点和 VPS 之间建立连接

问题描述

我试图将数据从现场的 php 发送到节点 js,以监听 VPS 上的某个端口。当我使用 jquery ajax 发出请求时,它会返回我想要的内容,但是当我使用 cUrl 从 php 向服务器发出请求时,它不会返回任何内容('')而不会出现一些错误。在我的 linux 控制台中,我看到它没有收到任何请求。cUrl 请求只是空虚......我尝试了许多 cUrl 请求,但它没有返回任何结果。可能是因为我的托管?或者也许我做错了什么?

var express = require('express');

var bodyParser = require('body-parser');

var cors = require('cors');

var app = express();

//Note that in version 4 of express, express.bodyParser() was

//deprecated in favor of a separate 'body-parser' module.

app.use(bodyParser.urlencoded({ extended: true })); 

//app.use(express.bodyParser());

app.listen(5300, function() {

  console.log('Server running at http://127.0.0.1:5300/');

});

app.use(bodyParser.json());

app.use(cors());

app.use(bodyParser.urlencoded({extended: false}));

app.all('/push', function(req, res) {

console.log(req.body); // 18

console.log(req.method);
console.log(req.headers);
console.log(req.url);
res.status(200).json({data:req.body}); // will give { name: 'Lorem',age:18'} in response
});

标签: javascriptphpnode.jsapachehttp

解决方案


我必须在我的托管管理菜单中打开端口。


推荐阅读