Sometimes, the data submitted by some requests is not a common Parameter Name: Key-value pair of the ing relationship of parameter values, such as the data submitted by the public platform server to the developer's specified URL, is the xml string... sometimes, the data submitted by some requests is not a common Parameter Name: Key-value pairs of the ing relationship such as parameter values. For example, the data submitted by the public platform server to the developer's specified URL is an xml string, at this time, you cannot use the java request. getParameter ("parameter name") cannot be obtained through $ _ POST ['parameter name'] in php. The solution for this data is as follows:
request.setCharacterEncoding("utf-8");StringBuilder buffer = new StringBuilder();java.io.BufferedReader reader=null;try{/*** getReader() * Retrieves the body of the request as character data using a BufferedReader* getInputStream() * Retrieves the body of the request as binary data using a ServletInputStream.*/reader = request.getReader();String line=null;while((line = reader.readLine())!=null){buffer.append(line); }}catch(java.io.IOException e){e.printStackTrace();}finally{if(null!=reader){try {reader.close();} catch (java.io.IOException e) {e.printStackTrace();}}}String res = buffer.toString();System.out.print(res);
Note: getReader () and getInputStream () can be called only once and cannot be called simultaneously.
Php code
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
Note:
The html from enctype attribute specifies how to encode the form data before it is sent to the server. The default value is "application/x-www-form-urlencoded ".
Application/x-www-form-urlencoded: The transmitted data is encoded as a key-value pair. the backend can directly obtain the data through request. getParameter ().
Text/plain, data is encoded in plain text format, which does not contain any control or format characters.
Multipart/form-data, the data to be transmitted must use the multimedia transmission protocol. Because multimedia transmission involves a large amount of data, it is required that the file to be uploaded must be post.
During file upload, the encoding type used should be "multipart/form-data". It can send text data and upload binary data.