前言:
在用IE瀏覽器時訪問tomcat項目時,頁面報400錯誤,后台錯誤:
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
在網上查得資料時因為Tomcat版本在7以后會對http頭進行驗證,不符合規范的就會拋出異常
而IE瀏覽器無法對URL自動轉義
解決辦法:
1.使用encodeURI函數
2.JS使用post請求
//發送POST請求跳轉到指定頁面
function httpPost(URL, PARAMS) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
return temp;
}