java中post时中文乱码
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时中文乱码的更多相关文章
- java中解决request中文乱码问题
request乱码问题(当我们提交的数据中含有中文信息时),分两种情况: 通过post方式提交数据给Servlet Servlet服务端部分代码: public void doPost(httpSer ...
- 解决Java中的HttpServletResponse中文乱码问题
response.setHeader("Content-type", "textml;charset=UTF-8"); response.setCharacte ...
- Windows平台下在Emacs中使用plantuml中文乱码问题(已解决)
Windows平台下在Emacs中使用plantuml中文乱码问题(已解决) */--> code {color: #FF0000} pre.src {background-color: #00 ...
- 解决Java保存到数据库中文乱码问题,加useUnicode=true&characterEncoding=UTF-8
Java保存到数据库中文乱码, 解决方法如下: 我们在连接MySQL数据库的时候一般都会在url后面添加useUnicode=true&characterEncoding=UTF-8,但是问什 ...
- SpringMVC学习系列-后记 解决GET请求时中文乱码的问题
SpringMVC学习系列-后记 解决GET请求时中文乱码的问题 之前项目中的web.xml中的编码设置: <filter> <filter-name>CharacterEnc ...
- git status 显示中文和解决中文乱码
目录 git status 显示中文和解决中文乱码 解决git status不能显示中文 解决git bash 终端显示中文乱码 通过修改配置文件来解决中文乱码 git status 显示中文和解决中 ...
- 使用PLSQL Developer时中文乱码问题
使用PLSQL Developer时中文乱码问题 一.问题: 执行一些查询结果有中文的SQL语句,显示不了中文,显示???. 二.产生的原因: 客户端与服务器端的编码不一致造成的. 三.解决方案: 1 ...
- RStudio中,出现中文乱码问题的解决方案
RStudio中,出现中文乱码问题的解决方案解决步骤:1.设置RStudio文本显示的默认编码:RStudio菜单栏的Tools -> Global Options2.选择General -&g ...
- curl提交数据时中文乱码
1.使用curl提交数据时中文乱码解决: <?php $testJSON=array('name'=>'中文字符串','value'=>'test'); foreach ( $tes ...
随机推荐
- C# 日期格式转【转】
使用:DateTime.ToString的方法(String, IFormatProvider)转换格式 using System; using System.Globalization; Strin ...
- QStandardItemModel-Delegate
//delete.h #ifndef DELEGATE_H #define DELEGATE_H #include<QItemDelegate> #include<QModelInd ...
- 自动更新补丁Security Update for Internet Explorer 10 for Windows Server 2008 R2 x64 Edition (KB2964358)失败
下载http://www.microsoft.com/zh-CN/download/details.aspx?id=42581手动安装成功.
- [CC]LOD技术
ccGLWindow::paintGL() | ccGLWindow::fullRenderingPass(...) | ccGLWindow::drawBackground(context, ren ...
- centos7作为web服务器优化
centos7作为web服务器优化 原文 http://itindex.net/detail/51140-centos7-web-服务器 1.加大打开文件数的限制(open files) 查看 uli ...
- postgresql查询的处理过程
本文简单描述了Postgresql服务器接收到查询后到返回给客户端结果之间一般操作顺序,总的流程图如下: 第一步: 客户端程序可以是任何符合 PostgreSQL 协议规范的程序,如 JDBC 驱动. ...
- delphi中exit,abort,break,continue 的区别
from:http://www.cnblogs.com/taofengli288/archive/2011/09/05/2167553.html delphi中表示跳出的有break,continue ...
- One of the best logo fonts "Klavika"
Download link: http://fontsgeek.com/search?q=Klavika
- 个人训练记录-赛码"bestcoder"杯中国大学生程序设计冠军赛
A.Movie 题意是给n个线段,要求求出是否存在三个不相交的线段,是的话输出yes,否则输出no.根据贪心的想法,可以先找出右端点r'最小的线段,他是三条线段中最左的那条,再找出左端点l'最大的线段 ...
- linux更改 DNS 的一般方式
一.第一种方法(常规方法) 在 Linux (笔者用fedora) 下当使用 NetworkManager时,更改 DNS 的一般方式: 修改 /etc/resolv.conf 文件, 添加 &quo ...