Tag: post

在节点express中请求body undefined

在节点expression式中,当我尝试从窗体访问post值时,它显示请求体未​​定义的错误。 这是我的代码, http.createServer(function(req, res) { var hostname = req.headers.host.split(":")[0]; var pathname = url.parse(req.url).pathname; if (pathname==="/login" && req.method ==="POST") { console.log("request Header==>" + req.body.username ); }).listen(9000, function() { console.log('http://localhost:9000'); }); 请任何人帮我find为什么请求正文显示未定义。

Angular 2的http post是作为空对象或在密钥端发送的

我试图发送数据从angular2到节点js在我的angular码是服务器端 addCrib(data:any) { let bodyString = data; let headers = new Headers({ 'Content-Type': 'application/json' }); return this.http.post('http://localhost:8000/addcribs',data , {headers:headers}).map(res => res.json()).subscribe( data => console.log(data) ); } 和在服务器端 addcribs: function(req,res){ var x = req.body; console.log(x); // {} with application/json and { '{data….}':''} with application/x-www-form-urlencoded let crib = new Cribs({id:0, type:req.body.type,price:req.body.price,address:req.body.address,description:req.body.description,bedrooms:req.body.bedrooms,bathroom:req.body.bathroom,area: req.body.area,image:req.body.image}); crib.save(function(err,crib){ if(!err){ res.json({success:true}); } }) […]

2 jQuery AJAX post req与同一个对象

我想要做的是这样的: <form> <input type="button" class="btn btn-warning" id="follow" value="Follow"> </form> <script type="text/javascript"> $('#follow').click(function(){ $.ajax({ url: '/follow' , type: 'POST' , cache: false , data: { user: '<%= username %>' } , complete: function() { }, success: function(data) { }, error: function() { console.log('process error'); }, }); $('#follow').attr('value', 'Following'); $('#follow').attr('id', 'unfollow'); }); $('#unfollow').click(function(){ $.ajax({ url: '/unfollow' , […]

ajax POST JSON数组到Nodejs服务器删除密钥

解决! 看到这个post底部的解决scheme…我已经被困在这个问题约2天,现在开始找我。 我想发布一个Json数组到我的节点服务器(跨域),并将其插入到云数据库。 这个问题更多的是关于以正确的格式获取JSON。 这里是我的客户端JSON和AJAX: function stress(){ var start = new Date().getTime(); $.ajax({ type: 'POST', url: 'url/', crossDomain: true, data: JSON.stringify(products), dataType: 'json', contentType: "application/x-www-form-urlencoded; charset=UTF-8", success: function(responseData, textStatus, jqXHR) { var end = new Date().getTime(); var millis = (end – start); var duration = (millis/1000); alert(responseData.msg +'Duration(seconds): ' + duration); }, error: function (responseData, […]

尝试HTTP请求时获取连接ECONNREFUSED 127.0.0.1:80

我正尝试使用本机node.js http模块向news.google.com发出http请求。 当我尝试以下操作时,出现connect ECONNREFUSED 127.0.0.1:80错误 var http = require('http'); var payload = JSON.stringify({ name: 'John Smith', email: 'john.smith@smith.com', resume: 'https://drive.google.com/open?id=asgsaegsehsehseh' }); var options = { hostname: 'https://news.google.com', path: '/', method: 'GET' }; var httpRequest = http.request(options, function(request, response) { console.log('STATUS', response.statusCode); response.setEncoding('utf8'); response.on('data', function(chunk) { console.log('BODY:', chunk); }); response.on('end', function() { console.log('No more data in […]

如何获得快递js的邮寄请求?

我试图得到一个小的服务,我写了后variables,但似乎无法得到它在我的app.post方法的请求variables。 我相信这是我处理请求的方式。 是否有额外的步骤,我必须采取处理的要求? 我也尝试使用express.bodyParser(),但我有一个错误,说这是不赞成。 以下是我的小node.js文件: var express = require('express'); var app = express(); app.use(express.json()); // posting method : curl -X POST http://localhost:8080/post-page -d name=ArrowKneeous // to look at the req I found it better to start using: // nohup node testPost.js > output.log & app.post('/post-page',function(req,res){ var name= req.body.name; //undefined console.log('name is :' + name); //object […]

在express / node中使用发布的表单数据时遇到问题

目前这是我所拥有的: 这是我的Post方法 app.post('/barchartentry', function(req, res){ res.render('barchart', { title: 'EZgraph: Bar Chart', barValues: req.body.myInputs, labelValues: req.body.myLabel}); }); 这是我在翡翠的看法: extends layout block appendHeader link(rel='stylesheet', href='stylesheets/barchart.css') block content include navbar canvas(id='canvas' width="800" height="600") include copyright block appendScripts script(src='js/barchart.js') 在这个视图中的JS文件,我需要访问我在这个文件中发送的数据 $(document).ready(function() { var values = barValues; var labels = labelValues; console.dir(barValues); var canvas = document.getElementById("canvas").getContext("2d"); canvas.fillStyle="#BFBFBF"; canvas.fillRect(0,0,800,600); canvas.fillStyle="#000000"; canvas.beginPath(); […]

POST请求与node.js中的数据

我怎么能发送带有数据的POST请求(例如一些variables)到https服务器并将结果显示给最终用户?

如何限制节点中简化HTTP请求的内容长度响应?

我想设置简化的HTTP请求()客户端软件包来中止太大的HTTP资源的下载。 假设request()被设置为下载一个url,并且资源大小是5千兆字节。 我想request()在10MB之后停止下载。 通常,当请求获得答案时,它会获得所有的HTTP标题以及后面的所有内容。 一旦你操作数据,你已经有了所有的下载数据。 在axios中,有一个名为maxContentLength的参数,但是我找不到任何类似于request()的东西。 我还必须提及,我不是要捕获一个错误,而只是至less下载头文件和资源的开始。

Expressjs POST错误:TypeError:无法读取未定义的属性“标题”

我想了很多,为什么这会引发这个错误: Configuring Listening on 2000 TypeError: Cannot read property 'title' of undefined at /home/abdulsattar/learning/node/express/index.js:9:20 index.js: var express = require("express"), app = express.createServer(); app.get("/", function(req, res) { res.send('<form action="/new" method="post"><input type="text" name="title" /><input type="submit" /></form>'); }); app.post("/new", function(req, res) { res.send(req.body.title); }); app.configure(function() { console.log("Configuring"); app.use(express.bodyParser()); }); var port = process.env.PORT || 2000; app.listen(port, function() { […]