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

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

  

  1. //在controll中进行调用;
  2. String content = HttpJsonUtils.getPostByTextPlain(request);
  3. //根据json数据中对象的key值及其类型取出相应的参数值
  4. JSONObject jsObject = JSONObject.fromObject(content);
  5. try {
  6. usermob = jsObject.getString("usermob");
  7. cpid = jsObject.getString("cpid");
  8. spid = jsObject.getString("spid");
  9. type = jsObject.getString("type");
  10. ordertime = jsObject.getString("ordertime");
  11. canceltime = jsObject.getString("canceltime");
  12. endtime = jsObject.getString("endtime");
  13. channelcode = jsObject.getString("channelcode");
  14. province = jsObject.getString("province");
  15. area = jsObject.getString("area");
  16. ordertype = jsObject.getString("ordertype");
  17. videoid = jsObject.getString("videoid");
  18. } catch (Exception e) {
  19. LOGGER.info("发生错误*****" + e.getMessage());
  20. }    

  

request中获取post的json对象数据content-type=“text/plain”的更多相关文章

  1. php中json对象数据的输出转化

    php中json对象数据的输出转化 public function get_my_now_citys(){ $datas=$this->_post('datas'); //前台js脚本传递给后端 ...

  2. Ajax请求php返回json对象数据中包含有数字索引和字符串索引,在for in循环中取出数据的顺序问题

    //php中的数组数据格式 Array ( [all] => Array ( [title] => ALL [room_promotion_id] => all ) [best_av ...

  3. 通过反射将request中的参数封装到对象中

    import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.text.SimpleDateFo ...

  4. PHP如何通过Http Post请求发送Json对象数据?

    因项目的需要,PHP调用第三方 Java/.Net 写好的 Restful Api,其中有些接口,需要 在发送 POST 请求时,传入对象. Http中传输对象,最好的表现形式莫过于JSON字符串了, ...

  5. Android中获取网页表单中的数据实现思路及代码

    在Android中获取网页里表单中的数据具体实现代码如下,感兴趣的各位可以参考过下哈,希望对大家有所帮助 MainActivity如下: 复制代码 代码如下: package cn.testjavas ...

  6. Android中获取网页表单中的数据

    MainActivity如下: package cn.testjavascript; import java.util.StringTokenizer; import android.os.Bundl ...

  7. 一个利用pojo类从前端页面request中获取参数的小框架~

    写之前不知道Spring已经实现这样的功能,所以傻傻的写了这个东西! 实现原理挺有趣的在此记录一下.从去年十月参加java开发以来自己终于有了点小进步. 好开心. 解决问题(详解):前端form表单提 ...

  8. 在Express 中获取表单请求体数据

    在Express 中获取表单请求体数据 获取 GET 请求参数 获取 POST 请求体数据 安装 配置 获取 GET 请求参数 Express 内置了一个 API , 可以直接通过 req.query ...

  9. 将XML文件中的内容转换为Json对象

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;u ...

随机推荐

  1. F - New Distinct Substrings (后缀数组)

    题目链接:https://cn.vjudge.net/contest/283743#problem/F 题目大意:给你一个字符串,然后让你求出不同的子串的个数. 具体思路:首先,一个字符串中总的子串个 ...

  2. JS获取今天和上个月的今天

    function getLastMonth(){ var now=new Date(); var year = now.getFullYear();//getYear()+1900=getFullYe ...

  3. 数据库操作之整合Mybaties和事务讲解 5节课

    1.SpringBoot2.x持久化数据方式介绍          简介:介绍近几年常用的访问数据库的方式和优缺点 1.原始java访问数据库             开发流程麻烦           ...

  4. SRS服务器搭建,ffmpeg 本地推流,srs从本地拉流

    参考: https://github.com/ossrs/srs/wiki/v2_CN_SampleFFMPEG git clone https://github.com/ossrs/srs cd s ...

  5. SpringBoot拦截器的注册

    (1).编写拦截器 package cn.coreqi.config; import org.springframework.util.StringUtils; import org.springfr ...

  6. 身份证号校验原理及JavaScript实现

          在网站中,总有各种各样的表单,用户使用表单来向服务器发送数据,进行交互. 然而,代代相传的经验是,永远不要信任用户的输入,一定要对数据进行验证.如果使用不经验证的表单,轻则会有大量无效提交 ...

  7. wget安装pip和pip3

    pip的安装 1.1 pip下载 wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2 ...

  8. pyspider使用

    #!/usr/bin/env python # -*- encoding: utf-8 -*- # Created on 2018-11-08 22:33:55 # Project: qsbk fro ...

  9. centos7 部署 docker ce

    =============================================== 2019/4/9_第1次修改                       ccb_warlock === ...

  10. 分布式调用技术 RPC VS REST

    一 分布式调用大体上就分为两类,RPC式的,REST式的,两者的区别主要是就是: 1. RPC是面向动作的(方法调用) 2. REST是面向资源的(URL表示资源,HTTP动词表示动作) 从变现形式来 ...