Comments (8)
request.body.readAll().toString()
from fibjs.
@xicilion 使用你说的这个 request.body.readAll().toString()
好像不行。
代码
var http = require('http');
var mq = require('mq');
var application = function (req){
var protocol = req.protocol;
var method = req.method;
var request_uri = req.address;
var query_string = req.queryString;
var headers = req.headers.toJSON();
var cookies = req.cookies.toJSON();
// content-type 支持有问题,目前不支持 application/json
var form = req.form.toJSON();
// *** HTTP BODY ***
var body = req.body.readAll().toString();
var body_size = req.length;
var remote_port = req.stream.remotePort;
var remote_address = req.stream.remoteAddress;
var local_port = req.stream.localPort;
var local_address = req.stream.localAddress;
console.log( body );
};
var server = new http.Server(8080, application);
server.run();
HTTP Request
curl -X PUT -d '{"uuuu":"34564p910521"}' "http://127.0.0.1:8080/path1/cgi.py?pwd=3465&abc=bbc" -H 'TEST: ASDAS'
错误提示
HttpHandler: TypeError: Cannot read property 'toString' of null at application (app.js:17:34)
from fibjs.
你之前成功获取过 form,所以 body 内容已经被读取出来了。如果你还想重读,可以先 req.body.rewind();
from fibjs.
@xicilion 谢谢。
另外一个问题,由于我自己需要去 headers
里面读取 content-type
,但是 底层实现似乎没有考虑大小写问题,也没有对数据进行修整。所以我必须得先在 js 里面遍历所有的 key
才能取到我想要的 'content-type' 的值。
对于这个问题,能否在底层 比如统一小写,或者 首字母大写呢 ?
:))
from fibjs.
@xicilion 不对哦,读取了 form
之后,再使用 req.body.rewind();
重读 返回的是 undefined
.
from fibjs.
req.body.rewind() 不是读操作,是指针复位操作,之后再用 readAll 读取。
headers 查询是不区分大小写的,你测一下。
from fibjs.
你区分了大小写,是因为你把 header toJSON 转换成 JS 的 Object 了。
from fibjs.
@xicilion Thx.
from fibjs.
Related Issues (20)
- How to get field or result data types(eg. varchar, date, time, timestamp) of a sql query in DbConnection?
- Can support the argument Buffer for Stream.read()? It's useful when have a customized buffer management
- How to fetch row from DbConnection instead of all data?
- How to access column value of result set by column index in db module?
- Redis模块的incr/decr返回值错误
- Decryption of block requires a full block in cipher.encrypt() HOT 1
- The parameter data of process.stdin.read() in async mode is undefined in fibjs src "test\process\exec.parallel_stdin.js" HOT 1
- "Error: [20011] Invalid input data." in http.get/post when the length of a response header value >= 4084 but the client curl command ok! HOT 3
- Add LoongArch new-world CI HOT 1
- missing `fullsrc.zip` for `0.37.0` release HOT 2
- 为什么要移除gd模块呢 HOT 1
- 当content-type不为application/x-www-form-urlencoded这个时,读取req.form报错 HOT 3
- 希望增加redis模块对执行lua脚本的支持 HOT 6
- The process exit code 0 is incorrect after the fibjs process crashes HOT 1
- Fatal error in Module::Evaluate when executing a *.mjs HOT 1
- HTTP/3 or QUIC Support HOT 5
- Dynamic TLS Certificates HOT 21
- V8 Torque Language
- How to access or determine the main module HOT 1
- How to save PKey pem into a file with a password? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fibjs.