IE瀏覽器報400錯誤:Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986


前言:

在用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;
}


免責聲明!

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



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