vue http请求 报错 415 ;400

http 返回 415: 

content-type 问题 ,改为json 即可

// 请求超时 请求头
axios.defaults.timeout = 10000
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';

http 返回 400 :

POST http://localhost:8001/users 400
:8080/#/:1 Uncaught (in promise) undefined

 

400错误为 前后台接口字段没有对应上   ,

在net work中查看发现:

{"timestamp":1578295334514,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"JSON parse error: Unrecognized token 'phone': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'phone': was expecting ('true', 'false' or 'null')\n at [Source: java.io.PushbackInputStream@32e961bc; line: 1, column: 7]","path":"/users"}

还来查看自己的封装的post方法 ,发现对data传参进行了序列化,:

直接修改为 params即可。

还有 (in promise )undefined  查看自己的封装的post请求:

/** 
 * post方法,对应post请求 
 * @param {String} url [请求的url地址] 
 * @param {Object} params [请求时携带的参数] 
 */
export function post(url, params) {    
    return new Promise((resolve, reject) => {         
        axios.post(url, QS.stringify(params))        
        .then(res => {            
            resolve(res.data);        
        })        
        .catch(err => {            
            reject(err.data)        
        })    
    });
}

在调用时候,只定义了 res=》  ,没有 err=> 参数

 应该为:

login(this.user).then(res => {
                        log.info('登录成功')
                        // this.$router.push('/dosomething/sport')
                        this.$Message.info('登录成功')
                    },error=>{
                        log.error('..error')
                    })

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值