Loopback.iorest连接器 – json发布不工作
我试图用loopback-rest-connector代理一个rest服务。 远程rest服务方法是POST,需要一个参数。 当我用查询string调用环回端点时,一切正常。 当我与身体json对象调用服务时,我得到的错误是所需的variables是未定义的,但参数是在对象ctx.req.body内。 回环没有看到它们。 我试图添加bodyparser中间件,但它也没有工作。
Datasource.js
{ "db": { "name": "db", "connector": "memory", "file": "db.json" }, "rest": { "name": "rest", "connector": "rest" }, "geoRest": { "connector": "rest", "debug": "true", "operations": [{ "template": { "method": "POST", "url": "https://url/endpoint", "headers": { "accept": "application/json", "content-type": "application/json", "Authorization": "sdfsdf" }, "body": { "address": "{^address:string}", "country": "{country:string}" } }, "functions": { "geocode": ["address", "country"] } }] } }
模型定义
{ "name": "geoRest", "plural": "geoRests", "base": "Model", "strict": true, "idInjection": false, "properties": {}, "validations": [], "relations": {}, "acls": [], "methods": [] }
型号configuration
"geoRest": { "dataSource": "geoRest", "public": true }
尝试使用form
而不是body
。 所以修改后的template
部分应该如下所示:
"template": { "method": "POST", "url": "https://url/endpoint", "headers": { "accept": "application/json", "content-type": "application/json", "Authorization": "sdfsdf" }, "form": { "address": "{^address:string}", "country": "{country:string}" } },
使用form
将发送您的参数,就像使用POST
方法提交表单一样,因此作为请求主体的一部分。
当使用body
或req
发送它附加到请求url,即基本上以查询参数的forms。
- 导出variables“路由器”具有或正在使用来自外部模块的名称“路由器”,但无法命名
- 为什么我的AngularJS / Express / Socket.io应用程序不能提供socket.io.js文件?
- EmberJS Express API | TypeError:app.route不是module.exports的函数
- 如何在套接字事件中呈现新的玉视图?
- 我想在点击一个button时在node.js服务器上触发一次server-sent-event
- angular与节点
- Node.js和underscore.js – 模板
- 如何在Express.js中共享控制器之间的通用逻辑?
- 帕格 – 编译后错误的嵌套 – 包括vs扩展