Workaround: The rest class cannot get the parameters sent by the HTTP put request

Source: Internet
Author: User
Tags html form http request



The rest class passes the string id = request.getparameter ("id") and can get the ID parameter value passed by the URL

However, the arguments in the put cannot be obtained, as follows


The following are from: http://dbscx.iteye.com/blog/828167

the definition of Put and post:
Controversy over the role of using put and post to insert new resources. New and updated definitions are available in the HTTP1.1 protocol.
Because all browsers do not support the Put method when submitting HTML form data (support for Get and POST), it is difficult to determine which method is the most sensible to use in which case.
The definition of restful is:
Get is used to retrieve a known Resource representation.
Post is used to create a new, dynamically named Resource.
Put is used to edit known Resource. Do not use it to create Resource.
Delete is used to remove known Resource.

Problem:
The HTTP protocol put method uses Tomcatapi,httprequest.getparameter () when using HTTP body to submit parameters, and cannot get parameter values.
Note: If the URL with the Get method is followed by a parameter, the parameter value can be obtained.

Reason:
It is possible that the API can only parse the GET, post form submission. Some other traditional MVC frameworks have similar phenomena.

Solution:       Java code protected void DoPut (HttpServletRequest req, HttpServletResponse resp) throws Servletexception, IOException {       BufferedReader in = new BufferedReader (New InputStreamReader (Req.getinputstream ()));       String Line;   while (line = In.readline ())! = null) System.out.println (line); }

Manually parse incoming parameters using the original input stream.

Get HTTP request types such as GET, POST, PUT, delete, etc.

HttpServletRequest request;

Request.getmethod ();


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.