Tag: http

有效负载字节与实际字节不同

我有一个问题,当用户发送图像数据,它保存在服务器上的损坏。 所以,我基本上有这样的设置: – api . index.js – methods . users.js (我已经删除了与问题无关的文件) 在API文件之外,有一个server.js ,每当访问api.example.com时都会启动它。 (基本上像一个VirtualHost) 话虽如此。 这是问题: ./api/index.js (问题点) // All this essentiall does is get the get the whole payload as a buffer. req.on("data", function(chunk){ // Potential problem area. req.api.payload = ((req.api.payload) ? (Buffer.concat([req.api.payload, chunk])) : (chunk)); }); req.on("end", function(){ // Check if we're on […]

Angular $ http POST从ExpressJS中获得null

我在后台没有经验,并与Node一起工作,尝试设置一个$ http POST请求来发送表单到Express。 每次发出请求时,我的callbackdata都是null 。 也许我的快车路线configuration不正确? 我正在使用Angular与Express / Node进行通信,通过nodemailer(我已经正确configuration)发送一封电子邮件。 这是我的$http POST请求: 客户端/服务/电子邮件/ emailer.js angular.module('public').factory('EmailerService',function($http) { return { postEmail: function(emailData, callback) { console.log('call http with object', emailData); $http({ method: 'POST', url: 'http://my-website.com/server/routes/emailer', data: emailData, headers: { "Content-Type": "application/json" }, responseType: 'json' }).success(function(data, status, headers, config) { console.log('success', data, status); }).error(function(data, status, headers, config) { console.log('error', data, […]

Node中的API请求返回错误

我使用一些请求参数向Sphere Engine API发出一个简单的http请求。 但是,我不能解释这个错误。 API规范: http : //sphere-engine.com/services/docs/compilers#status 码: http = require('http') ; var info = { sourceCode: 'print 3+4', language: 4, input: '' } ; var infoString = JSON.stringify(info); var options = { host: 'api.compilers.sphere-engine.com', port: 80, path: '/api/v3/submissions?access_token=b11bf50b8a391d4e8560e97fd9d63460', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': infoString.length } } ; var req = http.request(options,function(res) […]

NodeJS HTTP服务器和Console.log

我有一个简单的HTTP服务器 require('http').createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World!'); console.log('Got a request'); }).listen(4000); 但是,当我运行它“有一个请求”被写在控制台3次。 任何想法为什么?

在setTimeout中closuresnode.js http服务器的区别

以下的node.js程序不会退出: var http = require('http'); var server = http.createServer(function (req,res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337,'127.0.0.1'); server.close(); 但是这个呢: var http = require('http'); var server = http.createServer(function (req,res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337,'127.0.0.1'); function closeServer() { server.close(); }; setTimeout(closeServer,1); 没有连接到服务器。 有人可以解释程序之间行为改变的原因吗? 我刚刚在Windows 7上使用node.js版本0.12.5尝试了这一点。

节点 – 如何发送连续的HTTP响应回到客户端

我在节点js上工作,这对我来说是非常新的。 在这里,我有以下function,我从JS调用Http请求,并等待从Http响应返回的响应。 在这里,我得到了正确的答复,但在我的情况下,我在传感器设备上工作。 所以,我需要从HTTP获得连续的响应。 我正在使用 msg.res.send(200, 'Thanks for the request '); 并向客户发送“谢谢您的请求”。 但是,如果我使用 msg.res.send(200, 'Thanks for the request '); msg.res.send(200, 'Thanks for the request '); 像这样,第一个工作正常,第二个错误如下 错误:发送后无法设置标题。 可以请帮我解决这个问题,因为我需要从HTTP到客户端的持续响应。 提前致谢

expression得到根事件不起作用

当我请求本地主机:8080 /聊天?K = 1和D = 1它写入“聊天页”控制台,并正常工作。 但是,当我试图得到本地主机:8080根事件不写“索引页”,它会自动获取index.html,即使我设置索引为false。 这是我的代码; var path = require('path'); var express = require('express'); var encData; var appointmentKey; var urlGetDataAreValid = false; var app = express(); app.use(express.static(path.join(__dirname, 'static'), { index: false })); app.get('/', function(req, res, next) { console.log("INDEX PAGE"); res.sendFile('static/error.html'); }); app.get('/chat', function(req, res, next) { console.log("CHAT PAGE"); encData = req.param('d'); appointmentKey = […]

快速请求处理超时?

我有一个小的API,可以根据请求运行subprocess,并以最终的输出作为响应。 处理可能需要5-10-30分钟,没关系。 然而,Express会在一段时间后断开连接,并loggingPOST /api/v1/check – – ms – -即使subprocess的输出仍然得到处理,它永远不会返回到客户端。 请求是使用jQuery进行的。 我怎样才能使这项工作正常? 谢谢。

Angular2 / TypeScript&HTTP:如何将对象附加到组件?

我试图显示一个restAPI的项目名称列表。 我在响应observable上调用map并订阅获取parsing的items对象。 如何将对象附加到组件并在html模板上显示item.name的列表? import { Component, bootstrap } from 'angular2/angular2'; import { Http, HTTP_PROVIDERS } from 'angular2/http'; @Component({ selector: 'item-app', viewProviders: [HTTP_PROVIDERS], templateUrl: 'app/content.html' }) class ItemsComponent { items: Object; constructor(http: Http) { http.get('http://localhost:3000/api/items') .map(response => response) .subscribe( items => this.items = items ); } } <ul> <li *ng-for="#item of items"> {{ item.name }} </li> […]

使用Angular routeProvider和Express路线

我正在尝试使angular的routeProviderpipe理我的应用程序的所有路线。 我在angular(客户端)的app.js文件中相应地定义了我的路由: (function(){ var app = angular.module("Crowdsourcing", ["ngRoute"]); app.config(function($routeProvider){ $routeProvider .when("/single/:street/:buildingNumber/:apartmentNumber", { templateUrl: "/views/single.html'", controller: "ListingCtrl" }) .otherwise({redirectTo:"/"}); }); }()); 然而,当在浏览器上写入一个URL(例如/ single)时,试图由我的后端express / node api来处理这个请求。 因此,它不会被find,因为后端路由是例如/ api / foo。 我如何确保Angular的routeProvider始终pipe理我的请求? 更重要的是应用程序的基本stream程是什么? 当客户端编写一个URL时,应用程序如何知道url是由express js还是由routeProvider处理?