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中解决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 ...
SpringMVC学习系列-后记 解决GET请求时中文乱码的问题
SpringMVC学习系列-后记 解决GET请求时中文乱码的问题 之前项目中的web.xml中的编码设置: 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 ...
maven测试时中文乱码问题解决方法
pom.xml增加-Dfile.encoding=UTF-8配置,如下: org. ...
随机推荐
SQL Server如何提高数据库备份的速度
对于一个数据库完整备份来说,备份的速度很大程度上取决于下面两个因素:读磁盘数据.日志文件的吞吐量,写磁盘数据文件的吞吐量. 下图是备份过程中磁盘的变化情况: 读吞吐量 读吞吐量的大小取决于磁盘读取数据 ...
Java 8 VM GC Tunning Guide Charter 7-8-b
第七章 并发gc Java 8提供两种并发gc,CMS和G1 Concurrent Mark Sweep (CMS) Collector This collector is for applicati ...
Redis Cache 简介
Microsoft Azure Redis Cache 是基于流行的开源Redis Cache 1.Microsoft Azure Redis Cache 可分为以下几个级别: Basic – 单节点 ...
HashMap 与 HashSet 联系
HashMap实现 Map接口 HashSet实现Collection接口 HashSet底层是HashMap 好的 记住这个就可以了 HashSet只存放key, value: private ...
2.抽取代码(BaseActivity)
知识点 俩种退出程序的方法 复制集合 同步的用法 字符数组 工厂模式,生产fatgment,解决了碎片重复创建的问题 全局上下文 actionbar用法 fargmentadapter,当viewpa ...
html5 javascript 事件练习3随机键盘