jar包
commons-httpclient-3.0.jar
commons-logging.jar commons-codec-1.3.jarweb.xml需要加入以下配置:
<!-- 模拟HTTP的调用,写的一个http接口 -->
<servlet> <servlet-name>http服务文件名</servlet-name> <servlet-class>服务文件路径</servlet-class> </servlet> <servlet-mapping> <servlet-name>http服务文件名</servlet-name> <url-pattern>/页面访问路径</url-pattern> </servlet-mapping>http服务端解析jsonInputStream ins = req.getInputStream(); byte[] temp = new byte[1024]; ByteArrayOutputStream baStream = new ByteArrayOutputStream(); int count = 0; while((count = ins.read(temp))!=-1) { baStream.write(temp, 0, count); } if(baStream.size()!=0){ logger.info("=========传输的JSON String ======>>" + new String(baStream.toByteArray(),"UTF-8")); String strJSON=new String(baStream.toByteArray(),"UTF-8"); if (strJSON != null &&strJSON.startsWith("\ufeff")) { strJSON = strJSON.substring(1);//去空格 } JSONObject json=JSONObject.fromObject(strJSON);//解析strJSON String a = json.getString("a"); ........ //处理逻辑 ......... List
//不知道代码对不对,需要小伙伴们去验证呀。