Comments (9)
request data 只接受 JSON 格式的数据, JavaScript object 是不行的, 你可以尝试:
POST /orders
{"custom":{"id":"1","name":"john"},"orderItems":[{"quantity":10,"product":{"id":"1","name":"com","price":2.1}}]}
from node-odata.
Thx,it's done.
from node-odata.
还有一个问题:
.before(function (entity) {...}) 这个before方法里可以对request内容进行更改吗?这样可以不必重定义post等方法? 怎么做?
from node-odata.
可以的.
server.resource('orders', order)
.post().before(function (entity) {
entity.custom.name = "zack";
});
from node-odata.
@TossShinHwa 你好,如果request data的json数据里面包含了中文,POST会失败。都是英文的话不会返回ERROR。试试下面这段代码呢?看你那边会不会。
var http = require('http');
var bookBody = {
"title": "黑客与画家",
"price":9.89
}
var bookBodyString = JSON.stringify(bookBody);
var options = {
host: 'localhost',
port:'3000',
path: '/books',
method: 'POST',
headers: {
'Accept': '/',
'Content-Type':'application/json',
'Content-Length': bookBodyString.length
}
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function(data) {
console.log(data);
});
res.on('err',function(data){
console.log(data);
});
});
req.write(bookBodyString);
req.end();`
from node-odata.
这么取长度是不对的.
'Content-Length': bookBodyString.length
你可以考虑去掉这个参数, 让他自动计算, 就不会报错了.
from node-odata.
谢谢,果然是中文的坑。或者改成下面获取长度也可以避免。
Buffer.byteLength(bookBodyString, 'utf8')
from node-odata.
Great! 我之前都没有手动去处理过 req 的 length 问题, 学习了.
Sent from my iPhone
On May 18, 2016, at 21:41, 冯云 [email protected] wrote:
谢谢,果然是中文的坑。或者改成下面获取长度也可以避免。
Buffer.byteLength(bookBodyString, 'utf8')—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
from node-odata.
node test.js
{"title":"黑客与画家","price":9.89,"id":"7f9224d6-3b8c-4a14-9606-b665e17cec7d"}
我刚刚看到,调试的时候也是报错误,后台我对比curl,去掉了 content-length,就ok了
from node-odata.
Related Issues (20)
- Accept header
- Service document
- $select query option by get by id
- Deep objects and dot as property name
- How to use this with existing express instance? HOT 1
- Async Auth support HOT 1
- Skipping saving to db inside the post/put().before HOT 7
- asynchronous calls inside the post/put().before HOT 2
- A better way to declare a resource. HOT 3
- How do i get _id property? HOT 1
- Can I host on SSL? HOT 1
- Generate service according edmx/metadata HOT 1
- JSON Patch support for partial updates on resource HOT 1
- Parenthesis are not supported in filter HOT 1
- Please show example with mongodb and how it is accessed/ queried
- Critical and high vulnerability from npm audit
- Metadata Endpoint
- Node version corresponding package-lock.json
- some tests fails each run, but each time different test
- $format query option
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 node-odata.