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

Source: Internet
Author: User
Tags rfc

The small program before and after the use of Get method to pass the times wrong. But in the development platform and Apple test is all right, on the Android phone to report this error, guess the reason is that get passed the Chinese characters.

Tried the next in the background output from the foreground to get the parameters, but the background nothing to get, direct error.

Finally replaced the Chinese in the URL with the ID, because the search function can not replace the Chinese, changed to a POST request.

Reference:
Encoding process for "Java EE" get and POST requests
Get request the way to solve the problem of Chinese parameter garbled

There are many reports of this error on the Internet because of the special characters:
Some versions of Tomcat strictly follow the RFC 3986 specification for access resolution,
The RFC 3986 specification defines that only English letters (A-ZA-Z), Numbers (0-9),-_.~4 special characters, and all reserved characters are allowed in a URL
(The following characters are specified in RFC3986 as reserved characters:! * ' ();: @ & = + $,/? # []).
This error is reported in the reserved field in the passed parameter (example: "{") that is not in RFC3986. Example: Http://localhost:8080/index.do? {id:123}
Solve:
1. Remove special characters from the URL
2. URL encoding of parameters
3. Using Post submission
4. Replace the lower version of Tomcat
5. Add the last line in Conf/catalina.properties:
Org.apache.tomcat.util.buf.udecoder.allow_encoded_slash=true
Online also said add the following sentence to allow Forbidden characters: | {}
tomcat.util.http.parser.httpparser.requesttargetallow=| {}
Ref: 71716829

About URL encoding of parameters:

Example: to the URL of the | | to encode
(1) URL code for the foreground:

encodeURI ("http://localhost:8080/app/handleResponse?msg=name|id|" )> http://localhost:8080/app/handleresponse?msg=name%7cid%7c

(2) Encoding parameters only:

encodeURIComponent ("msg=name|id|" )> msg%3dname%7cid%7c

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.