• HttpServletRequest通过InputStream获取参数


        /**
    	 * 获取回调body
    	 * @param request
    	 * @return
    	 * @throws IOException
    	 */
    	public String getBody(HttpServletRequest request) throws IOException {
    		String body;
    		StringBuilder stringBuilder = new StringBuilder();
    		BufferedReader bufferedReader = null;
    		try {
    			InputStream inputStream = request.getInputStream();
    			if (inputStream != null) {
    				bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
    				char[] charBuffer = new char[128];
    				int bytesRead = -1;
    				while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
    					stringBuilder.append(charBuffer, 0, bytesRead);
    				}
    			} else {
    				stringBuilder.append("");
    			}
    		} catch (IOException ex) {
    			throw ex;
    		} finally {
    			if (bufferedReader != null) {
    				try {
    					bufferedReader.close();
    				} catch (IOException ex) {
    					throw ex;
    				}
    			}
    		}
    		body = stringBuilder.toString();
    		return body;
    	}
    

      

  • 相关阅读:
    virtual
    微软MBS intern笔试
    Ubuntu Linux Green hand
    Coding style
    abstract
    Jquery Ajax请求标准格式
    Hashtable的简单实用
    C#中GET和POST的简单区别
    WIN7 64位机与32位机有什么区别
    一个加密解密类
  • 原文地址:https://www.cnblogs.com/wanhua-wu/p/12370554.html
Copyright © 2020-2023  润新知