Tag:

为什么PUT请求体未定义?

我正在向我的koajs服务器发出以下请求: $.ajax({ type : 'PUT', // this.request.body undefined server side // type : 'POST', // this.request.body all good server side url : url, data : body, dataType : 'json' }) 但在服务器端, this.request.body总是未定义的。 如果我将请求types更改为POST,它工作正常。 有任何想法吗? 编辑 我正在使用koa-route 。 编辑2 刚刚意识到我正在使用koa-body-parser ,这可能更相关。

Node.js $ http PUT请求不向服务器返回任何内容

我正在开发一个pipe理客户信息的应用程序。 我是新来的MEAN堆栈,不能为我的生活弄清楚我在这里做错了什么。 当我从视图中单击“更新客户”时,控制台打印更新的信息,但是当我尝试将该信息发送到服务器并更新我的表时,我什么也得不到。 客户实体与以前一样。 风景 <div class="col-sm-12" id="addButton" style="padding: 10px;" > <button class="btn btn-primary" ng-click="update()" ng-disabled="editCustomerForm.$invalid">Update Customer</button> 控制器 $scope.update = function(){ console.log($scope.existingCustomer); $http.put('/customers/' + $scope.existingCustomer._id, $scope.existingCustomer).success(function(response) { refresh(); $scope.existingCustomer={}; $scope.editOldCustomer = false; }) }; server.js文件 app.put('/customers/:id', function (req, res) { console.log(req.body); var id = req.params.id db.customers.findAndModify({ query: {_id: "mongojs.ObjectId(id)"}, update: {$set: {name: req.body.name, email: req.body.email, […]

无法使用FTPClient node.js模块上传两个或更多文件

我正在使用节点和node-ftp模块。 我需要上传两个文件到另一个服务器,我可以上传一个文件,但是当我尝试上传两个文件时,它会抛出错误。 根据他们的API,这是发送文件的代码 var fs = require('fs'); conn.put(fs.createReadStream('/var/www/videoComplete/'+ videoID +'.flv'), '/home/wowza/content/'+ videoID +'.flv', function(e) { console.log(fileName + '.flv uploaded to Streaming Server :)'); conn.end(); }); 这工作正常,但如果我想要做两个文件,我假设我将不得不重复该function,但它不会工作。 有谁知道如何使用FTPClient发送两个或更多的文件 这是我正在执行的代码 conn = new FTPClient({ host: 'serverIP' }); conn.on('connect', function() { conn.auth('user', 'pass', function(e) { if (e) throw e; var fs = require('fs'); conn.put(fs.createReadStream('/var/www/ce-videoComplete/'+ videoID +'.flv'), '/home/wowza/content/'+ videoID […]

Mongoose:如何replace一个子文档数组?

我已经build立了一个包含子文档“contacts”的mongoose用户模式。 子文档“contacts”是包含实际联系人(引用另一个用户对象)和一些与“友谊”有关的数据的联系人对象的集合。 在我的前端应用程序中,我现在可以通过添加或删除用户到我的联系人列表来pipe理联系人。 前端将这些更改保存为HTTP PUT请求到服务器。 PUT请求包含整个用户对象,或多或less地replace数据库上的用户对象。 不幸的是,它不可能取代子文档集合。 你只能推新的或删除它们。 这里是模式: var UserSchema = new Mongoose.Schema({ username: { type: String, index: { unique: true, sparse: true }, required: true, lowercase: true, trim: true }, email: { type: String, index: { unique: true, sparse: true }, required: true, lowercase: true, trim: true }, contacts: [ContactSchema] }); var ContactSchema […]

抓住webhook node.js

我正在尝试捕获由Node.js中的Aftership API所做的PUT / webhook请求。 每次需要做推送通知时都会发出一个PUT请求,我正在使用Parse发送通知,但是我需要一些来自webhook的数据。 webhook的标题看起来像Content-Type: application/json并包含这些数据: ts – 事件发生的UTC unix时间戳 事件 – 事件的名称(用于跟踪更新,值将为'tracking_update') msg – 有关事件发生的消息的详细信息,格式如下。 我将如何去得到跟踪号码,slug和token值在节点或js中的自定义字段字典? { "event": "tracking_update", "msg": { "id": "53aa94fc55ece21582000004", "tracking_number": "906587618687", "title": "906587618687", "origin_country_iso3": null, "destination_country_iso3": null, "shipment_package_count": 0, "active": false, "order_id": null, "order_id_path": null, "customer_name": null, "source": "web", "emails": [], "custom_fields": {}, "tag": "Delivered", "tracked_count": 1, "expected_delivery": null, […]