public static String doPost(String urlStr, Map<String, Object> paramMap) throws Exception {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(SERVLET_POST);
String paramStr = prepareParam(paramMap);
conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
conn.setRequestProperty("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*");
conn.setRequestProperty("Accept-Language", "zh-cn");
conn.setRequestProperty("UA-CPU", "x86");
conn.setUseCaches(false);
conn.setConnectTimeout( * );
conn.setReadTimeout( * );
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Charset", "utf-8");
OutputStream os = conn.getOutputStream();
os.write(paramStr.toString().getBytes("utf-8"));
os.close(); String result = "";
if (conn.getResponseCode() == conn.HTTP_OK) {
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String line;
while ((line = br.readLine()) != null) {
result += line;
}
System.out.println(result);
br.close();
return result;
}
return result;
}

HttpURLConnection 返回汉字乱码(全是问号)的更多相关文章

  1. springmvc 返回汉字乱码

    1.删除配置文件中的<mvc:annotation-driven  /> 2.添加如下配置 <bean class="org.springframework.web.ser ...

  2. JAVA将汉字转换为全拼以及返回中文的首字母,将字符串转移为ASCII码

    import net.sourceforge.pinyin4j.PinyinHelper;import net.sourceforge.pinyin4j.format.HanyuPinyinCaseT ...

  3. 安卓+servlet+MySql 查询+插入(汉字乱码解决)

    问题: 安卓程序,通过servlet连接MySQL数据库,并实现查询和插入(修改,删除类似). 其中遇到的最大的问题是:汉字乱码问题(查询条件有汉字乱码.servlet的汉字到数据乱码.安卓通过ser ...

  4. 通过pinyin4j将汉字转换为全拼 和 拼音首字母

    /** * 汉字转换为拼音 包含多音字,包含生母zh,ch,sh的 */ public void toPinYinAll(){ String initials = "zh,ch,sh&quo ...

  5. 汉字转全拼音函数优化方案(SQLServer),值得你看看

    函数要求实现功能 select 函数名 ('你好,我是追索') 返回的结果(ni hao , wo shi zhui suo) 解决方案一: 解决方案一 /* 根据汉字获取全拼 1.生成所有读音临时表 ...

  6. 解决EditPlus在设置了UTF-8之后,编写的HTML页面仍出现汉字乱码问题

    解决EditPlus在设置了UTF-8之后.编写的HTML页面仍出现汉字乱码问题   相信有些同学在使用EditPlus编写HTML页面时发现,尽管已经设置好了UTF-8的编码格式.但却发现HTML页 ...

  7. vue 获取汉字的全拼、简拼、首拼

    1.封装公共方法,获取汉字的全拼.简拼.首拼 export const Pinyin = { _JMcode:{ "-":"", "—":& ...

  8. python 处理中文 读取数据库输出全是问号

    ref:http://www.cnblogs.com/zhoujie/archive/2013/06/07/problem1.html 1.python连接mssql数据库编码问题 python一直对 ...

  9. 解决SpringMVC的@ResponseBody返回中文乱码

    SpringMVC的@ResponseBody返回中文乱码的原因是SpringMVC默认处理的字符集是ISO-8859-1,在Spring的org.springframework.http.conve ...

随机推荐

  1. centos7.4上安装python3环境的坑

    前言:为了将爬虫项目布置到服务器上,才有了今天这一下午的坑,必须记录 不要动现有的python2环境!不要动现有的python2环境!不要动现有的python2环境! 解压 tar -xvf Pyth ...

  2. spring jpa nativequery in与修改

    参考 https://blog.csdn.net/a3025056/article/details/79022816 @Modifying@Transactional /* 如果在事务中使用需加上此注 ...

  3. 正则表达式pattern属性

    你发现自己多久匆匆编写一些正则表达式验证一个特定的文本. 多亏了新的pattern属性,我们可以在标签处直接插入一个正则表达式. <form action="" method ...

  4. [译] 什么阻塞了 DOM?

    原文地址:https://www.keycdn.com/blog/blocking-the-dom/原文作者:BRIAN JACKSON 当我们谈到web性能或者优化页面级别的速度时,非常重要的一点是 ...

  5. 100-days: Three

    Title: Singapore(新加坡) set to raise retirement ages as seniors stay healthier be set to do sth.  准备做某 ...

  6. 安装SQLserver2008r2出现 试图执行未经授权的操作

    安装时取消对兼容模式的勾选,重新安装就可以了. 或者加上   以管理员身份运行,兼容性设置,以管理员身份运行

  7. [leetcode]449. Serialize and Deserialize BST序列化与反序列化BST

    Serialization is the process of converting a data structure or object into a sequence of bits so tha ...

  8. Bootstrap(10) 进度条媒体对象和 Well 组件

    一.Well 组件这个组件可以实现简单的嵌入效果. <!-- //嵌入效果 --> <div class="well">Bootstrap</div& ...

  9. NPOI创建DOCX常用操作

    1.  创建文档 XWPFDocument m_Docx = new XWPFDocument(); 2.  页面设置 //1‘=1440twip=25.4mm=72pt(磅point)=96px(像 ...

  10. vue2.0后台系统

    参考网址: http://www.cnblogs.com/linxin/p/6509897.html