關於delete請求,后台接收不到數據


在前端用axios需要這樣寫

/**
* 刪除數據
*/
export function del(url, data = {}) {
return axios.delete(url, { data: qs.stringify(data) })
}

在瀏覽器中傳輸參數是在Request Payload中的,與以往的formdata不同

后台接收需要額外的方法

后台要想從Request Payload中得到自己想要的數據,就要從流中來獲取數據,具體的代碼為

ong evalutorId = null;

//從Request Payload中獲取數據,從流中來獲取數據
ServletInputStream is;
try {
is = request.getInputStream();
int nRead = 1;
int nTotalRead = 0;
byte[] bytes = new byte[10240];
while (nRead > 0) {
nRead = is.read(bytes, nTotalRead, bytes.length - nTotalRead);
if(nRead > 0)
nTotalRead = nTotalRead + nRead;
}
// str為evalutorId=20
String str = new String(bytes, 0, nTotalRead, "utf-8");
String[] split = str.split("=");
evalutorId = Long.parseLong(split[1]);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

參考:https://blog.csdn.net/Your_heart_private/article/details/71436210


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM