Comments (8)
this.headers['content-type'] = 'application/json'
就行了,但不建议这么搞;如果这是一个提交json数据的请求,最好写一个独立的controller:this.proxy('test:test/post')
from gracejs.
现在遇到一个很奇怪的问题。
在执行this.proxy()方法前,修改了 content-type ( this.headers['content-type'] = 'application/json' )
但到java服务器端,content-type 仍然是 "application/x-www-form-urlencoded"
我用postman测试后端接口时,就不会出现这种问题??
from gracejs.
先不管重设content-type的方案,修改下你的ajax,直接发送一个application/json的请求,然后直接proxy到后端试试?
from gracejs.
我通过 ajax的post方法, 设定 contentType:"application/json" 后
url设置为java后台请求地址时,结果正确。
但,如果使用 proxy 后,再到java后台,结果仍然不正确。
from gracejs.
貌似找到原因了。
在 co-proxy.js 中:
function requestWap(param, options, callback) {
// 获取request参数
let opt = Object.assign({
uri: undefined, // 请求路径
method: undefined, // method
headers: undefined, // 头信息
json: false, // 是否是json数据
gzip: true, //是否gzip
timeout: 15000 // 超时时间
}, {
form: param.ctx.request.body
}, options);
form: param.ctx.request.body 把这个参数去掉,在java后台就正确了
from gracejs.
let opt = Object.assign({
uri: undefined, // 请求路径
method: undefined, // method
headers: undefined, // 头信息
json: false, // 是否是json数据
gzip: true, //是否gzip
timeout: 15000 // 超时时间
}, {
body: param.ctx.request.body
}, options);
把 form: param.ctx.request.body 修改为 body: param.ctx.request.body后就可以了。
不知道对其它地方有没有影响呢?
from gracejs.
赞!我升级下,跑下测试看看!
from gracejs.
我试了一下,如果直接把body注入到request的boay参数里,如果这个请求是一个Stream就会出问题;
这里是这样:如果当前请求content-type是application/json,则服务器收到的肯定是application/json;这里不建议再做什么转换
from gracejs.
Related Issues (20)
- 路由可以使用别的模式 HOT 1
- 多个post请求且有不同的form参数时,有好的解决方案吗? HOT 2
- Proxy-Post传XML参数时会被放进Form中。 HOT 1
- nunjucks 要添加个过滤器怎么加呢? HOT 1
- 模板引擎改为 nunjucks 出现找不到模板错误 HOT 1
- 建议添加 eslint, .editorconfig HOT 2
- proxy的500友好页怎么跳转
- controller 中如何某个引用的库 没有install 不报错,然后访问的时候404.有办法在编译的时候直接报错吗
- nunjucks 自定义过滤器 HOT 5
- 设置头字段中set-cookie为对应cookie 字段类型报错 HOT 1
- post支持xml吗 HOT 1
- proxy代理数据问题 HOT 1
- 数据库支持扩展 HOT 1
- `defaultCtrl.js` 里做鉴权时抛出`401`错误,无法进入default err handing! HOT 1
- 请问当页面输入URL地址时候如何把controller中的路由文件夹名字省略掉 HOT 2
- koa 新手求教
- 如何提高单点TPS, QPS HOT 5
- npm run dev 后 访问127.0.0.1:3000 报错 Cannot read property 'store' of undefined HOT 5
- session中间件报错,this.session是undefined HOT 2
- 运行start,页面返回Invalid hostname!
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 gracejs.