zoukankan      html  css  js  c++  java
  • request中获取post的json对象数据content-type=“text/plain”

    其实采用http://www.cnblogs.com/SimonHu1993/p/7295750.html中的方法一都能获取到,
    就是通过获取request中的流数据,拿到json数据,理论上应该适用各种content-type的请求数据。

    /**
    	 *获取 request 中用POST方式"Content-type"是
    	 * "text/plain"发送的 json数据 
    	 * @author: Simon
    	 * @date: 2017年8月6日 下午7:44:09
    	 * @param request
    	 * @return
    	 * @throws IOException
    	 */
    	public static String getPostByTextPlain(HttpServletRequest request) throws IOException{
    
    		BufferedReader reader = request.getReader();
            char[] buf = new char[512];
            int len = 0;
            StringBuffer contentBuffer = new StringBuffer();
            while ((len = reader.read(buf)) != -1) {
                contentBuffer.append(buf, 0, len);
            }
            String content= contentBuffer.toString();
            return content;
    	}
    

      

    //在controll中进行调用;
    String content = HttpJsonUtils.getPostByTextPlain(request);
    //根据json数据中对象的key值及其类型取出相应的参数值
    JSONObject jsObject = JSONObject.fromObject(content);
    			try {
    				usermob = jsObject.getString("usermob");
    				cpid = jsObject.getString("cpid");
    				spid = jsObject.getString("spid");
    				type = jsObject.getString("type");
    				ordertime = jsObject.getString("ordertime");
    				canceltime = jsObject.getString("canceltime");
    				endtime = jsObject.getString("endtime");
    				channelcode = jsObject.getString("channelcode");
    				province = jsObject.getString("province");
    				area = jsObject.getString("area");
    				ordertype = jsObject.getString("ordertype");
    				videoid = jsObject.getString("videoid");
    			} catch (Exception e) {
    				LOGGER.info("发生错误*****" + e.getMessage());
    			}    
    

      

  • 相关阅读:
    高精度不会的迅速暴击此处
    高精度不会的迅速暴击此处
    codevs3243:区间翻转,线段树
    codevs3243:区间翻转,线段树
    codevs3243:区间翻转,线段树
    [NOIP2010]关押罪犯
    [NOIP2010]关押罪犯
    [NOIP2010]关押罪犯
    [UVALive 6693]Flow Game计算几何,线代相交
    2017 省赛选拨 火车入站 CSU 1757 模拟
  • 原文地址:https://www.cnblogs.com/SimonHu1993/p/7295888.html
Copyright © 2011-2022 走看看