我WebRequest从C#发送一个POST 以及一个JSON对象数据,并希望在Node.js服务器中接收它,如下所示:
var express = require('express');
var app = express.createServer();
app.configure(function(){
app.use(express.bodyParser());
});
app.post('/ReceiveJSON', function(req, res){
//Suppose I sent this data: {"a":2,"b":3}
//Now how to extract this data from req here?
//console.log("req a:"+req.body.a);//outputs 'undefined'
//console.log("req body:"+req.body);//outputs '[object object]'
res.send("ok");
});
app.listen(3000);
console.log('listening to http://localhost:3000');
Run Code Online (Sandbox Code Playgroud)
此外,WebRequest通过以下方法调用POST的C#end :
public string TestPOSTWebRequest(string url,object data)
{
try
{
string reponseData = string.Empty;
var webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
if (webRequest != null)
{
webRequest.Method = "POST";
webRequest.ServicePoint.Expect100Continue = false;
webRequest.Timeout …Run Code Online (Sandbox Code Playgroud) 我安装了cairo和node-canvas.我尝试了一切,但仍然找不到模块.
sudo apt-get install libcairo2-dev
sudo npm install canvas
sudo npm install canvas -g
Run Code Online (Sandbox Code Playgroud)
如果我跑require('canvas'),我得到这个错误:
Error: Cannot find module '../build/Release/canvas'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object.<anonymous> (/home/tomas/node_modules/canvas/lib/bindings.js:2:18)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:32)
at Function._load (module.js:308:12)
at Module.require (module.js:354:17)
Run Code Online (Sandbox Code Playgroud)
我用Ubuntu linux
提前致谢.
我是Node.js的新手,我遇到了一个错误:
RangeError:超出最大调用堆栈大小
我无法解决问题,因为关于Node.js的其他stackoverflow问题中的大多数堆栈问题都涉及数百个回调,但我这里只有3个.
首先是一个fetch(findById)然后更新一个以后的保存操作!
我的代码是:
app.post('/poker/tables/:id/join', function(req, res) {
var id = req.params.id;
models.Table.findById(id, function(err, table) {
if (err) {
console.log(err);
res.send({
message: 'error'
});
return;
}
if (table.players.length >= table.maxPlayers) {
res.send({
message: "error: Can't join ! the Table is full"
});
return;
}
console.log('Table isnt Full');
var BuyIn = table.minBuyIn;
if (req.user.money < table.maxPlayers) {
res.send({
message: "error: Can't join ! Tou have not enough money"
});
return;
}
console.log('User has enought money');
models.User.update({
_id: req.user._id …Run Code Online (Sandbox Code Playgroud) 我是Play框架的新手.请解释下面警告的含义.
警告:node.js检测失败,sbt将使用基于Rhino的Trireme JavaScript引擎来运行JavaScript资源编译,这在某些情况下可能比使用node.js慢几个数量级.
我不想要任何使我的应用程序变慢的东西所以请建议我是否应该将JS Engine更改为Node.js,但我的PlayFramework项目在服务器端使用Java.
我有一台西门子1200 PLC.使用node-opcua客户端和Kepserver我能够读取变量并更改值.现在我想在KepServer中从node-opcua在PLC中创建一个新变量.

我曾尝试使用node-opcua服务器,因为在示例中我已经看到了如何创建变量,但是我收到错误,因为我正在尝试连接到KepServer所执行的相同端口.
var server = new opcua.OPCUAServer({
port: 49320, // the port of the listening socket of the server
resourcePath: "", // this path will be added to the endpoint resource name
buildInfo : {
productName: "MySampleServer1",
buildNumber: "7658",
buildDate: new Date(2014,5,2)
}
});
Run Code Online (Sandbox Code Playgroud)
我怎么处理创建一个新变量?并从node-opcua创建一个组标签?
是否可以在Kepserver中安装opcua服务器并创建直接连接到该服务器的变量?我的Kepserver位于:opc.tcp:// localhost:49320要连接到此Kepserver,我使用nodeopcua客户端:
var opcua = require("node-opcua");
var client = new opcua.OPCUAClient();
var endpointUrl = "opc.tcp://127.0.0.1:49320";
var the_session = null;
async.series([
// step 1 : connect to
function(callback) {
client.connect(endpointUrl,function (err) {
if(err) …Run Code Online (Sandbox Code Playgroud) public class Main {
public static void main(String[] args) {
System.out.println(B.x);
}
}
class A {
public static String x = "x";
}
class B extends A {
static {
System.out.print("Inside B.");
}
}
Run Code Online (Sandbox Code Playgroud)
问题:为什么输出将是:x.但不是:Inside B.x
我是Node.js和NPM的新手.我正在使用Node v0.10.0,当我运行npm install socket.io命令时,我收到以下错误:
C:\Users\USER\AppData\Roaming\npm\node_modules\socket.io\node_modules\socket.io-
client\node_modules\ws>node "C:\Users\USER\AppData\Roaming\npm\node_modules\npm\
bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(29
7,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.
TargetFrameworkVersion or PlatformToolset may be set to an invalid version nu
mber. [C:\Users\USER\AppData\Roaming\npm\node_modules\socket.io\node_modules\so
cket.io-client\node_modules\ws\build\bufferutil.vcxproj]
bufferutil.cc
c:\users\user\.node-gyp\0.10.0\deps\uv\include\uv-private/uv-win.h(32): fatal e
rror C1083: Cannot open include file: 'winsock2.h': No such file or directory [
C:\Users\USER\AppData\Roaming\npm\node_modules\socket.io\node_modules\socket.io
-client\node_modules\ws\build\bufferutil.vcxproj]
Run Code Online (Sandbox Code Playgroud)
我想这是一个构建错误所以我花了很多时间谷歌搜索和更新我的Windows SDK,Visual Studio,.Net Framework等.以某种形式,我得到上述错误.根据此链接https://connect.microsoft.com/VisualStudio/feedback/details/713415/erroneous-windows-sdk-x64-compilation-warning,警告可能是错误的,因为我在x64机器上.我确实看到winsock2.h位于C:\ Program Files\Microsoft SDKs\Windows\v7.1\Include中并包含在我的路径中.我的路径包含以下内容:
C:\Program Files\nodejs\;
C:\Program Files (x86)\Microsoft Visual Studio 8\VC\vcpackages;
C:\Program Files\Microsoft Windows Performance Toolkit\;
C:\Program Files …Run Code Online (Sandbox Code Playgroud) 我正准备memcached着
$memcached->set("item" , ["1" => "hello"]);
Run Code Online (Sandbox Code Playgroud)
任何在PHP中工作,
在带有memcached插件的Node.js中,我得到一个缓冲区而不是结果中的数组
<Buffer 61 3a 25 61 34 3a>
Run Code Online (Sandbox Code Playgroud)
我无法将这种缓冲区转换为数组
在Node.js中:
memcached.get("item" , function(err, data) {
console.log(data);
}
Run Code Online (Sandbox Code Playgroud)
你有什么办法吗?
我是Angular.js的新手并尝试为网站构建本地身份验证.我已经浏览了各种来源,单页应用程序中的身份验证非常有用.当我尝试在我的localhost中构建相同的代码时,我的代码进入循环.
app.post('/login',.....)在响应返回用户,但之后,尽管加载它是检查用户是否通过调用记录在管理页面 app.get('/loggedin',... ),并req.isAuthenticated()正在恢复false,即使登录后,它进入一个循环.我不明白为什么会这样,请帮助我.
服务器端代码
var express = require('express');
var http = require('http');
var path = require('path');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
//==================================================================
// Define the strategy to be used by PassportJS
passport.use(new LocalStrategy(
function(username, password, done) {
if (username === "admin" && password === "admin") // stupid example
return done(null, {name: "admin"});
return done(null, false, { message: 'Incorrect username.' });
}
));
// Serialized and deserialized methods when …Run Code Online (Sandbox Code Playgroud) 我使用Passport-Local Mongoose加密帐户的密码.但我不知道如何更改密码.
你能举一些文件或例子来做吗?谢谢.
node.js ×9
mongoose ×2
passport.js ×2
angularjs ×1
c# ×1
express ×1
inheritance ×1
java ×1
javascript ×1
kepserverex ×1
memcached ×1
mongodb ×1
node-canvas ×1
node-opcua ×1
npm ×1
passwords ×1
rhino ×1
socket.io ×1
static ×1
windows-7 ×1