Tag: http

基本的HTTP服务器瓦特/节点JS

我有点困难。 我是一般的新手,这是我本周为JavaScript课程分配的程序。 我们应该创build一个Web服务器,用于从文件系统提供文件,也可以实现Node模块。 它必须能够读取HTML,CSS,GIF和JS资源。 这些文件将被放置在与脚本相同的文件夹下,位于/ scripts和/ html目录下。 这里是我试图实现的逻辑,但是我的terminal不断告诉我path.extname(资源)是一个未定义的函数。 我知道这很难看,但是我仍然试图围绕这个概念。 任何帮助都会很好,我一直在想这一天过去。 'use strict'; // Load the file system module var fs = require('fs'); // load the http module var http = require('http'); // load the url module var url = require('url'); // load the path module var pathModule = require('path'); // The following function will be […]

通过HTTP访问LDAP目录?

我试图从本身不支持协议的设备访问LDAP目录。 我希望能够通过HTTP操作发送请求,运行LDAP查询,并以JSONforms返回结果。 我试图通过一个类似于LDAP客户端的Node.js服务器来做到这一点。 你可以在这里查看Gist。 几个问题: 这甚至有可能吗? 什么是authentication的最佳做法? 谢谢!

节点JS上的HTTP请求callback

嗨我想通过使用callback方法的http获得响应。 但是我得到一个错误,说callback不是一个函数。 module.exports.ipLookup = function (res, callback) { var http = require('http'); var str = ''; var options = { host: 'ip-api.com', port: 80, path: '/json/', method: 'POST' }; var str= ""; var req = http.request(options, function (res) { res.on('data', function (body) { str += body; }); res.on('end', function () { callback(str); }); }); req.end(); […]

在客户端使用AngularJS进行HTTP请求

成功完成本教程后 ,我开始构build我的应用程序路由,以处理在数据库中创build的一些虚拟模型,当我通过Postman应用程序请求它们时(使用以下URL:https://lab4-roger13.c9users .IO:8080 / API /书呆子)。 下一步是在AngularJS中创build一个服务,允许用户在客户端请求这些相同的信息。 在教程结束时,我留下了这个: angular.module('NerdService', []).factory('Nerd', ['$http', function($http) { return { // call to get all nerds get : function() { return $http.get('/api/nerds'); }, a : 2, // these will work when more API routes are defined on the Node side of things // call to POST and create a new […]

如何把不同的请求的响应放在与nodejs相同的文档中并请求?

嗨,我想把不同的请求的反应在同一个文件。 我有这个文件: var result = {google:"", twitter:"", facebook:""} 我想对这些网站(google.com,Facebook.com,twitter.com)做不同的GET请求,并把所有的结果放在通讯录中。 我尝试了嵌套的callback,但这样我必须先做谷歌调用,然后像这样的微博等: Request({ url:first_url, },function(err, response, body) { if (err) { request.log(err); }else{ risultato.google = body; Request({ url:second_url, },function(err, response, body) { if (err) { request.log(err); }else{ risultato.facebook = body; Request({ url:third_url, },function(err, response, body) { if (err) { request.log(err); }else{ risultato.twitter = body; console.log(result); } }); […]

AngularJS $ http无限调用

有人可以解释为什么$ http请求发送无限数量的请求到服务器? 在我的应用程序中,这个代码发送无限的请求到服务器 (function(){ var app = angular.module("GrahamsSocksProducts", ["ngCookies"]); app.controller("ProductsController", ["$controller", "$http", "$cookies", function($controller, $http, $cookies){ . . . this.setCookie = function(){ username = "Some random guy" alert(45) $http({ method : "GET", url : "http://_____________", params : { username : username } }).then(function(){ //do something }) } 但是,当我删除http请求时,只有一个请求被传递到服务器,如下所示: . . . this.setCookie = function(){ username […]

Nodejs请求:HPE_INVALID_HEADER_TOKEN

我使用request模块在某个页面上收到HPE_INVALID_HEADER_TOKEN 。 从我在Google上发现的情况来看,这是由于服务器响应错误/格式错误造成的,但后者不在我的控制之下。 我可以configuration请求来忽略无效的头文件,或只是给我处理整个原始响应?

HTTP响应string末尾的奇怪字符

我正在使用下面的nodejs包生成一些简单的restful API。 https://github.com/restify/node-restify 但是在响应json结尾处我得到了一个奇怪的字符。 服务器端代码与以上链接提供的相同。 我怎样才能去除%?

使用节点http模块上传文件

如何使用节点http模块(并且没有第三方库)将file upload到远程服务器? 我尝试了以下,但它不工作(我没有在服务器上的数据): function writeBinaryPostData(req, filepath) { var fs = require('fs'); var boundaryKey = Math.random().toString(16); // random string var boundaryStart = `–${boundaryKey}\r\n`, boundaryEnd = `\r\n–${boundaryKey}–`, contentDispositionHeader = 'Content-Disposition: form-data; name="file" filename="file.txt"\r\n', contentTypeHeader = 'Content-Type: application/octet-stream\r\n', transferEncodingHeader = 'Content-Transfer-Encoding: binary\r\n'; var contentLength = Buffer.byteLength( boundaryStart + boundaryEnd + contentDispositionHeader + contentTypeHeader + transferEncodingHeader ) + fs.statSync(filepath).size; […]

在Hapi.js中我可以redirect到一个不同的端点并设置一个statusCode?

如果用户没有通过authentication来查看特定的路由(例如: /admin ),Auth会抛出一个Boom unorthorized错误我希望能够Boom unorthorized到/login但仍然返回401 HTTP statusCode 。 我们已经尝试了下面的代码: const statusCode = request.output.payload.statusCode; if(statusCode && statusCode === 401) { return reply.redirect('/login').code(statusCode); } 当我们删除.code(statusCode)时, redirect工作,但我们理想地将401代码返回到客户端而不是302 ( redirect ) 或者 …是否是“ 最佳做法 ”返回302 …? 上下文:我们正在开发一个(可重用的 )插件来处理我们的Hapi App / API中的错误,其中一个特性是当auth失败时redirect到/login请参阅https://github.com/dwyl/hapi-错误#redirect到另一个端点 ,我们希望得到它“ 正确 ”,以便其他人可以使用它!