http://blog.chinaunix.net/uid-12348673-id-3335300.html

设置流的编码,就避免了乱码

public static String post(String path,String params) throws Exception{
HttpURLConnection httpConn=null;
BufferedReader in=null;
//PrintWriter out=null;
try {
URL url=new URL(path);
httpConn=(HttpURLConnection)url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setDoInput(true);
httpConn.setDoOutput(true);
System.out.print("params="+params);
//utf-8
PrintWriter ot = new PrintWriter(new OutputStreamWriter(httpConn.getOutputStream(),"utf-8"));
ot.println(params);
ot.flush();
//out=new PrintWriter(httpConn.getOutputStream());
//out.println(params); //out.flush(); //读取响应
if(httpConn.getResponseCode()==HttpURLConnection.HTTP_OK){
StringBuffer content=new StringBuffer();
String tempStr="";
//utf-8
in=new BufferedReader(new InputStreamReader(httpConn.getInputStream(),"utf-8"));
while((tempStr=in.readLine())!=null){
content.append(tempStr);
}
return content.toString();
}else{ throw new Exception("请求出现了问题!"); }
} catch (IOException e) {
e.printStackTrace();
}finally{
in.close();
// out.close();
httpConn.disconnect();
}
return null;
}

  

java中post时中文乱码的更多相关文章

  1. java中解决request中文乱码问题

    request乱码问题(当我们提交的数据中含有中文信息时),分两种情况: 通过post方式提交数据给Servlet Servlet服务端部分代码: public void doPost(httpSer ...

  2. 解决Java中的HttpServletResponse中文乱码问题

    response.setHeader("Content-type", "textml;charset=UTF-8"); response.setCharacte ...

  3. Windows平台下在Emacs中使用plantuml中文乱码问题(已解决)

    Windows平台下在Emacs中使用plantuml中文乱码问题(已解决) */--> code {color: #FF0000} pre.src {background-color: #00 ...

  4. 解决Java保存到数据库中文乱码问题,加useUnicode=true&characterEncoding=UTF-8

    Java保存到数据库中文乱码, 解决方法如下: 我们在连接MySQL数据库的时候一般都会在url后面添加useUnicode=true&characterEncoding=UTF-8,但是问什 ...

  5. SpringMVC学习系列-后记 解决GET请求时中文乱码的问题

    SpringMVC学习系列-后记 解决GET请求时中文乱码的问题 之前项目中的web.xml中的编码设置: <filter> <filter-name>CharacterEnc ...

  6. git status 显示中文和解决中文乱码

    目录 git status 显示中文和解决中文乱码 解决git status不能显示中文 解决git bash 终端显示中文乱码 通过修改配置文件来解决中文乱码 git status 显示中文和解决中 ...

  7. 使用PLSQL Developer时中文乱码问题

    使用PLSQL Developer时中文乱码问题 一.问题: 执行一些查询结果有中文的SQL语句,显示不了中文,显示???. 二.产生的原因: 客户端与服务器端的编码不一致造成的. 三.解决方案: 1 ...

  8. RStudio中,出现中文乱码问题的解决方案

    RStudio中,出现中文乱码问题的解决方案解决步骤:1.设置RStudio文本显示的默认编码:RStudio菜单栏的Tools -> Global Options2.选择General -&g ...

  9. curl提交数据时中文乱码

    1.使用curl提交数据时中文乱码解决: <?php $testJSON=array('name'=>'中文字符串','value'=>'test'); foreach ( $tes ...

随机推荐

  1. 关于xib的一些细节/ 真机调试/ GitLab

    ---------------------------------------------------------------------------------------------------- ...

  2. php数字索引数组去重及恢复索引

    $tmp = array('a','b','c','a'); $tmp = array_values(array_unique($tmp)); print_r($tmp);exit; //输出 Arr ...

  3. spring bean的重新加载

    架构体系 在谈spring bean的重新加载前,首先我们来看看spring ioc容器. spring ioc容器主要功能是完成对bean的创建.依赖注入和管理等功能,而这些功能的实现是有下面几个组 ...

  4. centos6.7下安装mvn 、安装elasticsearch下ik分词

    先说一下安装mvn步骤,如果已安装可以忽略: 在tmp目录下 1.建立mvn目录 mkdir mvn cd /tmp/mvn 2.下载 wget http://apache.fayea.com/mav ...

  5. 纯CSS实现下拉菜单及下拉容器等(纯CSS实现导航条及导航下拉容器)

    虽然网上类似甚至相同的案例有很多,但是我还是写下,以记下笔记,也可供大家参考 希望大家可以指导批评~~ 首先我们以列表ul li 来开始我们菜单也可以说导航条的制作: 在页面中我们首先构建以下XHTM ...

  6. js 转码 和 .Net 后台解码

    为防止 中文乱码,js传值要转码,当js 用 escape() 转码时,.Net 后台可以用 HttpUtility.UrlDecode() 进行解码. 例如:   document.cookie = ...

  7. OC ---- 字典集合 iOS学习-----细碎知识点总结

    实例方法的创建 NSDictionary *wukong = [[NSDictionary alloc] initWithObjectsAndKeys:", @"age" ...

  8. JAVASE02-Unit05: 集合操作 —— 查找表

    Unit05: 集合操作 -- 查找表 使用该类测试自定义元素的集合排序 package day05; /** * 使用该类测试自定义元素的集合排序 * @author adminitartor * ...

  9. python pip安装问题

    scipy-0.18.1-cp34-cp34m-win32.whl is not a supported wheel on this platform. 遇到该问题需要更新pip版本 1.更新pip: ...

  10. CXF WebService整合SpringMVC的maven项目

    首先推荐博客:http://www.cnblogs.com/xdp-gacl/p/4259481.html   http://blog.csdn.net/hu_shengyang/article/de ...