我现在的问题是,使用express解析web浏览器反馈回答的数据,mode解析失败,打印为Object,但是监查端口却有数据,请指点! 这是我html代码:
<head> <meta charset="utf-8"> // <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="Content-Type" Content="application/json;Charset=utf-8"> <title>Login Form</title> <link rel="stylesheet" href="http://10.10.103.234/css/style.css"> <script type="text/javascript" src="http://10.10.103.234/js/1.js"></script> <script type="text/javascript" src="http://10.10.103.234/js/2.js"></script> <style> #fly { width: 50px; height: 20px; background-color: red; } </style> </head> <body>用户登录
<form method="post" action="http://10.10.103.234:8000/index.html"><input type="text" id="username" name="username" value="yxy" placeholder="用户名">
<input type="password" id="password" name="password" value="" placeholder="密码">
<input type="text" name="checkNum" id="checkNum" value="" placeholder="验证码">
<input id="submit" type="submit" name="commit" value="登录">
</form><div class="login-help">
</div>
这是我js代码: var express = require(‘express’); var app = express(); var bodyparser=require(‘body-parser’); var router = express.Router(); app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: true })); app.use(express.static(‘public’)); app.use(express.static(‘views’));
app.get(’/’,function(req,res){ res.sendFile(/views/regin.html); });
app.post(’/index.html’,function(req,res){ console.log(“yangxiaoyu test!!!”); console.log(“post body:”+req.body); console.log(“post query:”+req.query); });
var server=app.listen(8000,function(req,rse){ var host = server.address().address; var port = server.address().port; console.log(‘app listening at http://%s’, port); });
这是打印: yangxiaoyu test!!! post body:[object Object] post query:[object Object]
这是端口数据: 0x0020: 5018 00ff e591 0000 7573 6572 6e61 6d65 P…username 0x0030: 3d79 7879 2670 6173 7377 6f72 643d 7978 =yxy&password=yx 0x0040: 7926 6368 6563 6b4e 756d 3d26 636f 6d6d y&checkNum=&comm
可以看到端口是有数据的,解析有问题,以下是我npm list: ├─┬ body-parser@1.0.0 │ ├── UNMET DEPENDENCY qs@~0.6.6 │ └── UNMET DEPENDENCY raw-body@~1.1.2 ├─┬ express@4.14.0 │ ├─┬ accepts@1.3.3 │ │ ├─┬ mime-types@2.1.13 │ │ │ └── mime-db@1.25.0 │ │ └── negotiator@0.6.1 │ ├── array-flatten@1.1.1 │ ├── content-disposition@0.5.1 │ ├── content-type@1.0.2 │ ├── cookie@0.3.1 │ ├── cookie-signature@1.0.6 │ ├─┬ debug@2.2.0 │ │ └── ms@0.7.1 │ ├── depd@1.1.0 │ ├── encodeurl@1.0.1 │ ├── escape-html@1.0.3 │ ├── etag@1.7.0 │ ├─┬ finalhandler@0.5.0 │ │ ├── statuses@1.3.1 │ │ └── unpipe@1.0.0 │ ├── fresh@0.3.0 │ ├── merge-descriptors@1.0.1 │ ├── methods@1.1.2 │ ├─┬ on-finished@2.3.0 │ │ └── ee-first@1.1.1 │ ├── parseurl@1.3.1 │ ├── path-to-regexp@0.1.7 │ ├─┬ proxy-addr@1.1.2 │ │ ├── forwarded@0.1.0 │ │ └── ipaddr.js@1.1.1 │ ├── qs@6.2.0 │ ├── range-parser@1.2.0 │ ├─┬ send@0.14.1 │ │ ├── destroy@1.0.4 │ │ ├─┬ http-errors@1.5.1 │ │ │ └── setprototypeof@1.0.2 │ │ └── mime@1.3.4 │ ├── serve-static@1.11.1 │ ├─┬ type-is@1.6.14 │ │ └── media-typer@0.3.0 │ ├── utils-merge@1.0.0 │ └── vary@1.1.0 ├─┬ mysql@2.12.0 │ ├── bignumber.js@2.4.0 │ ├─┬ readable-stream@1.1.14 │ │ ├── core-util-is@1.0.2 │ │ ├── inherits@2.0.3 │ │ ├── isarray@0.0.1 │ │ └── string_decoder@0.10.31 │ └── sqlstring@2.2.0 └── raw-body@0.0.1
请教各位,我哪里有问题?