post請求通過form表單的submit提交,url和請求體中都添加同樣的參數,會怎麼樣?

關於POST請求參數後端出現截取現象分析

概述

如果post請求通過form表單的submit提交,url和請求體中都添加同樣的參數,會怎麼樣?

事由

生產過程中出現參數被截斷的現象,一直定位不到問題。

覆盤

  • 1.測試demo
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<div>
		<button onclick="doPrint()">發送</button>
	</div>
</body>
<script>
	
	function doPrint(){
		var consArray = new Array();
		for(var i=0; i< 500; i++){
			consArray.push("5025303");
		}
		consArray.push("5053041");
		var args = new Object();
		args.consNo = consArray;
		printNoSelect(args);
	}

	function printNoSelect(args, preview) {
		var params = "";
		if (args) {
			for ( var prop in args) {
				params = params + "&" + prop + "=" + args[prop];
			}
		}
		var url = "http://localhost:8088/learn-web/helloWorld/postRequest.do?U="
				+ (new Date()).getTime() + params;
		PostWindow(url, args, '打印預覽');
	}

	/**
	 * 以post方式打開新頁面
	 * @param url
	 * @param data
	 * @param name
	 */
	function PostWindow(url, data, name) {
		var tempForm = document.createElement("form");
		tempForm.id = "tempForm1";
		tempForm.method = "post";
		tempForm.action = url;
		tempForm.target = name;
		for ( var prop in data) {
			var hideInput = document.createElement("input");
			hideInput.type = "hidden";
			hideInput.name = prop;
			hideInput.value = data[prop];
			tempForm.appendChild(hideInput);
		}
		document.body.appendChild(tempForm);
		tempForm.submit();
		document.body.removeChild(tempForm);
	}
</script>
</html>
@RequestMapping("/testPost")
	public String testPost(Model m, HttpServletRequest req) {
		m.addAttribute("consNo", "");
		return "testPost";
	}

@RequestMapping("/postRequest")
@ResponseBody
public String postRequest(HttpServletRequest req, HttpServletResponse res) {
    Map rptParas = new HashMap();
    Map parasMap = req.getParameterMap();
    Iterator it = parasMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        Object key = entry.getKey();
        Object value = entry.getValue();
        if ((key instanceof String) && (value instanceof String[])) {
            rptParas.put((String) key, ((String[]) (String[]) value)[0]);
        }
    }
    System.out.print(rptParas.get("consNo").toString().split(",").length);
    return "1";
}

在這裏插入圖片描述
在這裏插入圖片描述

  • 2.抓包分析

在這裏插入圖片描述
在這裏插入圖片描述

  • 3.源碼分析

在這裏插入圖片描述
在這裏插入圖片描述

總結

業務方面

  • 1.批量傳遞數據,如果是批量全選的話,完全可以一個ID信息都不需要。

  • 2.如果只有少數批量信息沒有被勾選,那麼可以嘗試傳遞這些沒有被勾選的信息,然後去後端過濾這些ID。

  • 3.有很多種方式可以做到把參數數據量的體積減下來,通訊效率會大大提高。

測試方面

  • 1.測試的時候,清除緩存再測試。

  • 2.如果在測試過程中初步懷疑是某一原因導致,就改原因多測試幾遍,測一遍肯定是不保險。

  • 3.多人測試的時候環境一定要同步,否則反饋的信息就不準確。

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