起因是在angular項目中使用axios發送post請求,向后台傳參后台一直無法接收,網上查了有說是請求頭設置不對,需要把Content-Type:application/x-www-form-urlencoded;charset=UTF-8
改了之后發現還是不行,后來終於找到原因,axios請求中params和data,不一樣,post需要把參數放在data中,get請求放在params中才行
//POST請求
sendIndentifyCodeServer(opt){ axios.post(`${environment.path}/IdentifyingCode/getVcode`,opt.data).then((response)=>{ if(opt.onSuccess){ opt.onSuccess(response); } }).catch(error=>{ if(opt.onFailed){ opt.onFailed(error); } }); }
//GET請求
sendIndentifyCodeServer(opt){
axios.get(`${environment.path}/IdentifyingCode/getVcode`,{params:opt.data}).then((response)=>{ if(opt.onSuccess){ opt.onSuccess(response); } }).catch(error=>{ if(opt.onFailed){ opt.onFailed(error); } }); }
