簡體   English   中英

卷曲到node.js的服務器。 但什么也不退。 如何使server.js返回200 json?

[英]Curl to node.js 's server. but not return anything. How can I make the server.js return 200 json?

我正在node.js上使用通知系統,並且嘗試在php中使用curl並將通知推送到它。

但是,每次我在終端或php中使用curl時,它都不會返回任何內容,但實際上會推送通知。

如何使此代碼返回200,而不是什么也不返回,並保持curl運行直到超時?

/* CONFIGURATION */

/* Web Server Config */
var _postpath = '/send';
var _listenport = 8888;
var _listenaddr = '0.0.0.0';  //use '0.0.0.0' to listen on all interfaces

/* Slave (sub) Redis Server Config */
var _channelfilter = '*';
var _sub_db_addr = '127.0.0.1';
var _sub_db_passwd_protected = true;
var _sub_db_passwd = 'secret';
var _sub_db_port = 6379;  //default redis port is 6379

/* Master (pub) Redis Server Config */
var _pub_db_addr = '127.0.0.1';
var _pub_db_passwd_protected = true;
var _pub_db_passwd = 'secret';
var _pub_db_port = 6379;  //default redis port is 6379

/* SocketIO Config */
var _loglevel = 1;

/* simple-pub-sub Config */
var _secretkey = "secret";


/* SERVER CODE -- DO NOT MODIFY */
redis = require('redis');
express = require('express');
socketio = require('socket.io');
fs = require("fs"),
pub = redis.createClient(_pub_db_port, _pub_db_addr); if (_pub_db_passwd_protected) {  }

sub = redis.createClient(_sub_db_port, _sub_db_addr); if (_sub_db_passwd_protected) { }
sub.on("pmessage", function(pattern, channel, json) { io.sockets.volatile.emit(channel, JSON.parse(json)); });
sub.psubscribe('*');

app = express.createServer(express.static(__dirname + '/public'),express.bodyParser());
app.listen(_listenport, _listenaddr);
app.post(_postpath, function(req, res){
  if(req.body.secretkey==_secretkey){
    delete req.body.secretkey; pub.publish(req.body.channel, JSON.stringify(req.body))
  }
});

io = socketio.listen(app);
io.configure(function () { io.set('log level', _loglevel) });

謝謝!

只需在帖子中發送200碼

app.post(_postpath, function(req, res){
  if(req.body.secretkey==_secretkey){
    delete req.body.secretkey; pub.publish(req.body.channel, JSON.stringify(req.body));
    res.send(200);
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM