使用流的方式去进行post请求解决中文乱码问题返回xml格式
/**
* 请求post
* @Title: getHttpURLConnection
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param: @param url1
* @param: @param paream
* @param: @return
* @param: @throws IOException
* @param: @throws JSONException
* @return: String
* @throws
* @author ecar
* @Date 2016-7-23 下午03:08:59
*/
private String getHttpURLConnection(String url1,String paream) throws IOException, JSONException
{
Long deviceId=1l;
URL url = new URL(url1);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/json;charset=utf-8");
connection.setConnectTimeout(80*1000);
connection.setReadTimeout(80*1000);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.connect();
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeLong(deviceId);
//最短
JSONArray array = new JSONArray(paream);
out.writeShort(array.length());
for(int i=0;i<array.length();i++){
JSONObject obj = array.getJSONObject(i);
out.write(obj.getString("time").getBytes("UTF8"));
double d = obj.getDouble("lon");
int lon = (int)(d * 1000000);
out.writeInt(lon);
d = obj.getDouble("lat") ;
int lat = (int)(d * 1000000);
out.writeInt(lat);
out.writeFloat((float)obj.getDouble("speed"));
out.writeFloat((float)obj.getDouble("direc"));
}
调用方式:
String ss = "[" ;
String date = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date());
Gps gps= PositionUtil.gcj_To_Gps84(Double.valueOf(split[1]), Double.valueOf(split[0]));//转化为84的坐标系
Gps gps1= PositionUtil.gcj_To_Gps84(Double.valueOf(split02[1]), Double.valueOf(split02[0]));//转化为84的坐标系
Gps gps2= PositionUtil.gcj_To_Gps84(Double.valueOf(split03[1]), Double.valueOf(split03[0]));//转化为84的坐标系
ss+="{\"time\":\""+date+"\",\"lon\":"+gps.getWgLon()+",\"lat\":"+gps.getWgLat()+",\"speed\":20,\"direc\":0},";
ss+="{\"time\":\""+date+"\",\"lon\":"+gps1.getWgLon()+",\"lat\":"+gps1.getWgLat()+",\"speed\":30,\"direc\":0},";
ss+="{\"time\":\""+date+"\",\"lon\":"+gps2.getWgLon()+",\"lat\":"+gps2.getWgLat()+",\"speed\":30,\"direc\":0}";
ss+="]";
String param=getHttpURLConnection(uriAPI+"/RouteTrafficInfoSearch?bizcode=fBAym29ZX11kVKbuQVnJ",ss);
System.out.println(param);
返回xml格式的数据
out.flush();
out.close();
DataInputStream in = new DataInputStream(connection.getInputStream());
int len = in.available();
byte[] b = new byte[len];
in.read(b);
// System.out.println(new String(b,"utf-8"));
return new String(b,"utf-8");
}
使用流的方式去进行post请求解决中文乱码问题返回xml格式的更多相关文章
- spring mvc 文件下载 get请求解决中文乱码问题
方案简写,自己或有些基础的可以看懂,因为没时间写的那么详细 方案1 spring mvc解决get请求中文乱码问题, 在tamcat中server.xml文件 URIEncoding="UT ...
- Idea中使用http请求解决中文乱码问题
以请求百度为例,使用如下代码即可解决: GET https://www.baidu.com User-Agent: Mozilla/.X MetaSr 1.0
- 详解get请求和post请求参数中文乱码的解决办法
首先出现中文乱码的原因是tomcat默认的编码方式是"ISO-8859-1",这种编码方式以单个字节作为一个字符,而汉字是以两个字节表示一个字符的. 一,get请求参数中文乱码的解 ...
- 使用过滤器(Filter)解决请求参数中文乱码问题(复杂方式)
前述: 在写这篇笔记之前,对笔记中的设计模式进行介绍: 本篇笔记中将要使用到的设计模式是:装饰(包装)设计模式 (1)装饰(包装)设计模式口诀: ...
- java web项目get,post请求参数中文乱码解决
[转载]原文地址:https://www.cnblogs.com/tom-plus/p/6392279.html 在开发过程中,有时候会碰到get,post请求参数中文乱码. 原因: Http请求传输 ...
- 使用SpringMVC参数传递时,解决get请求时中文乱码的问题
问题描述: 使用SpringMVC参数传递时, 遇到get请求中文信息时,页面应答会显示中文乱码. 解决办法: 一, 我们需要把request.getParameter(“参数名”)获取到的字符串先 ...
- SpringMVC学习系列-后记 解决GET请求时中文乱码的问题
SpringMVC学习系列-后记 解决GET请求时中文乱码的问题 之前项目中的web.xml中的编码设置: <filter> <filter-name>CharacterEnc ...
- [转]解决GET请求时中文乱码的问题
原文地址:http://www.cnblogs.com/liukemng/p/4178882.html 之前项目中的web.xml中的编码设置: <filter> <filter-n ...
- springMVC学习 四 请求的中文乱码解决
在使用SpringMVC时,同样有前端向后端发送请求,请求参数中有中文,需要解决中文乱码问题,在Spring中也是向java web中一样,通过一个过滤器来解决中文乱码. 这个过滤器在spring-w ...
随机推荐
- OAuth 开放授权 Open Authorization
http://oauth.net/ http://tools.ietf.org/html/rfc6749 http://reg.163.com/help/help_oauth2.html 网易通行证O ...
- 防止系统页面被加载进 iframe 子窗口
在controller的返回的响应头中添加 response.addHeader("x-frame-options", "DENY"); 即可
- ie浏览器和火狐浏览器对对容器宽度定义的差异
首先我们说说firefox和IE对CSS的宽度显示有什么不同: 其实CSS ’width’ 指的是标准CSS中所指的width的宽度,在firefox中的宽度就是这个宽度.它只包含容器中内容的宽度.而 ...
- sql 关键字的用法
coalesce( T.GoodsCode,'0') 若 T.GoodsCode 为NULL 这 用0替换 round(S.SaleEarning,2) 保留两位小数 SUBSTRING(zb.acc ...
- Android开发使用的常见第三方框架汇总
本文转载:http://blog.csdn.net/liuhaomatou/article/details/44857005 1.volley 项目地址 https://github.com/sman ...
- 怎么学好XXX
怎么学好数据库是一个比较大题目,数据库不仅仅是写SQL那么简单,即使知道了SQL怎么写,还需要很清楚的知道这条SQL他大概扫描了多少数据,返回多少数据,是否需要创建索引.至于SQL优化是一个比较专业的 ...
- webpack2版本四个核心概念
webpack 是一个现代的 JavaScript 应用程序的模块打包器(module bundler) 四个核心概念: --------------------------------------- ...
- webstorm里直接调用命令行
写代码写到一半要切换窗口出去敲命令行?webstorm的external tools可以帮你省下一点时间 举例说明,比如我要直接使用npm: ctrl+alt+s打开setting菜单,找到exter ...
- 迅为八核cortex a53开发板android/linux/Ubuntu系统
详情请点击了解:http://www.topeetobard.com 店铺:https://arm-board.taobao.com 核心板: 提供1G和2G内存版本,全机器焊接,杜绝手工,批量无忧. ...
- leetcode_712. Minimum ASCII Delete Sum for Two Strings
https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings/ 给定两个string s1,s2,从s1和s2中删除一些 ...