第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于Vue.axios 與 Servlet POST請求問題

關于Vue.axios 與 Servlet POST請求問題

慕標5832272 2019-05-19 14:05:29
首先我在vue.config.js 加上了devServermodule.exports = {    configureWebpack: config => {              },      devServer:{        proxy: {            "/api": {              target: "http://localhost:3000",            }          }      }  } 首先我用axios請求POSTaddUser:function () {      axios.post('/api/reguser?name=sds&password=2&age=1&sex=man&company=ali')      .then(function (response) {        console.log(response);      })      .catch(function (error) {        console.log(error);      });    }    然后我用Servlet的req.getParameter的方法獲取前端傳來的POST字段!我可以正常接受!然后我對數(shù)據(jù)做了封裝!addUser:function () {          axios.post('/api/reguser',{              data          })          .then(function (response) {            console.log(response);          })          .catch(function (error) {            console.log(error);          });        }    那么出現(xiàn)了一個問題就是axios會把data放在請求的body中,我后臺獲取不到這樣的數(shù)據(jù)了并且前端會報錯誤xhr.js?b50d:178 POST http://localhost/api/reguser 500 (Internal Server Error)dispatchXhrRequest @ xhr.js?b50d:178xhrAdapter @ xhr.js?b50d:12dispatchRequest @ dispatchRequest.js?5270:59Promise.then (async)request @ Axios.js?0a06:51Axios.<computed> @ Axios.js?0a06:71wrap @ bind.js?1d2b:9REGUSER @ store.js?c0d6:14wrappedMutationHandler @ vuex.esm.js?2f62:725commitIterator @ vuex.esm.js?2f62:391(anonymous) @ vuex.esm.js?2f62:390于是我查了相關問題,順利的解決了后端接受不到json對象的問題StringBuilder builder = new StringBuilder();        try {            BufferedReader bufferedReader = req.getReader();            char[] buff = new char[1024];            int len;            while((len = bufferedReader.read(buff)) != -1){                builder.append(buff,0,len);            }        }catch (IOException e){            System.out.println(e);        }但是我前端每次請求都會報錯POST http://localhost/api/reguser 500 (Internal Server Error)但是后端能正常的接受到數(shù)據(jù){"data":{"name":"23","password":"23","age":"23","sex":"男","company":"23"}}所以我很困惑為什么會這樣呢?
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻1784條經(jīng)驗 獲得超7個贊

getParameter拿的是 queryString 或者 表單 的數(shù)據(jù) 
如果需要拿json就要自己讀 body、反序列化

500是后端報錯,看后端的報錯輸出


查看完整回答
反對 回復 2019-05-19
  • 1 回答
  • 0 關注
  • 3350 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號