java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

前端 未结 3 463
别那么骄傲
别那么骄傲 2021-01-18 02:20
java.lang.IllegalArgumentException: 
Invalid character found in the request target. 
The valid characters are defined in RFC 7230 and RFC 3986

This

3条回答
  •  独厮守ぢ
    2021-01-18 02:44

    I encountered the same error when sending location of a file in a AJAX GET request.

    Error:

    java.lang.IllegalArgumentException: 
    Invalid character found in the request target. 
    The valid characters are defined in RFC 7230 and RFC 3986
    

    Since the location had characters which are not recognized. I.e. "C:///" etc, the error was thrown.

    The use of encodeURIComponent helped me fix the issue since it encodes the component.

    When you pass the Chinese characters make sure you add those inside "encodeURIComponent" method. In my case:

     $.ajax({
            type: "GET",
            url: 'removeFile?removeFileName=' + encodeURIComponent("C:///YO/Ed/PO/")
            data: {},
            dataType: 'json',
    

提交回复
热议问题