踩坑-springboot中讀取HttpServletRequest流的死循環

踩坑記錄  

在我們公司一個springmvc項目中有一個讀取HttpServletRequest流的方法,我把這個方法用在新的springboot項目中結果陷入死循環。經過很久的測試,發現這個方法用在springboot項目有問題,現在將這個坑記錄起來,方便自己,方便他人。

 

springmvc中HttpServletRequest讀取流的方法,該方法在springboot中調用會陷入死循環

String inputLine;
StringBuilder notifyXml = new StringBuilder();

try {
	while ((inputLine = request.getReader().readLine()) != null) {
		notifyXml.append(inputLine);
	}
		request.getReader().close();
	} catch (IOException e) {
			e.printStackTrace();
	}

springboot中建立緩衝流讀取

StringBuilder notifyXml = new StringBuilder();
  try {
	   BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream()));
	   String line;
	   while ((line = in.readLine()) != null) {
			notifyXml.append(line);
		}
  } catch (IOException e) {
	 e.printStackTrace();
  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章