$.ajax request request.getInputStream() can't get data problem

Add the parameter contentType to the request

1. In the case of no modification, calling request.getParameter() can get some data, that is, the data of url splicing parameters.

2. Without any modification, if you do not call request.getParameter() anywhere before, but directly call request.getInputStream(), you can get the data.

3. The original client uses the default request header Content-Type: application/x-www-form-urlencoded. After modifying this value to multipart/form-data or application/octet-stream, it can be obtained through request.getInputStream(). data, even if request.getParameter() has been called before, the final solution is of course for the client to modify the Content-Type.

 

 

$.ajax({
	  type: "post",
	  url: "。。。。。。。。。。。。。。",
	 data: {param1: 1, param2: 2},
	  //contentType: "application/json; charset=utf-8",//(可以)
	 //contentType: "text/xml",//(can)
	  //contentType:"application/x-www-form-urlencoded",//(可以)
	 dataType: "json",
	  success: function (data) {
		  if (data != "") {
			
		  }
	  }
})

 

 

 Finally, note that the three methods request.getParameter(), request.getInputStream(), and request.getReader() are conflicting, because the stream can only be read once. E.g: 

1. When the form content is encoded with enctype=application/x-www-form-urlencoded, first get the parameters by calling the request.getParameter() method, and then call request.getInputStream() or request.getReader(). to the content of the stream, because the system may read the data submitted in the form as a stream once when request.getParameter() is called, and vice versa. 
2. When the form content is encoded with enctype=multipart/form-data, even if request.getParameter() is called first, the data will not be obtained, but at this time, the request.getParameter() method is called to request.getInputStream() or request. There is no conflict with getReader(), even if the request.getParameter() method has been called, the data in the form can be obtained by calling request.getInputStream() or request.getReader(), while request.getInputStream() and request.getReader() are in The same response cannot be mixed, if mixed, an exception will be thrown.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326865242&siteId=291194637