javascript - 我试图在托管站点和 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
});
解决方案
我必须在我的托管管理菜单中打开端口。
推荐阅读
- android - 尝试在视图寻呼机的 onPageSelected 时在图像视图上做一些动画,但动画没有在 onPageSelected 中启动
- wordpress - 如何使用 WordPress 创建一个不仅仅是博客的网站
- android - 在 BlueStacks 上运行纯 32 位 ELF ARM 二进制文件
- regex - 正则表达式:如何在积极的回顾中包含多个换行符?
- c# - 使用 adobe javascript 将注释保存到 SQL Server 数据库中
- jquery - 在 jquery 数据表中显示数据库中的图像后,如何将图像转换为 pdf?
- python - 如何知道“tf.boolean_mask”返回的动态张量是否为空?
- css - 以下标签的 CSS 选择器
- java - 小程序无法在浏览器中正确显示
- python - 对于在迭代中简单地将值分配给矩阵,RAM 超出并且计算机挂起。任何想法?有什么更好的方法吗?