request中擷取post的json對象資料content-type=“text/plain”

來源:互聯網
上載者:User

標籤:通過   請求   發送   param   read   pen   exception   obj   key值   

其實採用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());}    

  

request中擷取post的json對象資料content-type=“text/plain”

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.