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. openjdk1.8 源码地址

    http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/656ab3b39178/src/

  2. ftp删除目录和文件,目录下有文件删除提示【550 Remove directory operation failed.】

      注意:目录下有文件,直接删除目录会失败,提示550 Remove directory operation failed. 必须先将目录下的文件都删除,才能删除目录   ftp命令行: ftp删除目 ...

  3. android通过命令行安装sdk

    在linux下没有界面化的安装sdk方式,所以需要通过下载zip包或命令行安装   一.通过tools下的android安装 1.进入到android工具 cd $ANDROID_HOME/tools ...

  4. 弹出序列(python)

    题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压 ...

  5. AttributeError: 'dict' object has no attribute 'iteritems'

    在python3.6中运行 sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse= ...

  6. poj3292(筛法+打表)

    题目链接:https://vjudge.net/problem/POJ-3292 题意:定义4n+1数(简称H数),H数分为三类:unit,即为1; H-primes,只能分解为1×自身,类似于我们平 ...

  7. 第十章 优先级队列 (c)堆排序

  8. 消除游戏源码 Match 3 Jewel Full 298 Levels

    Match 3 Jewel Full 298 Levels 一款unity3d编写的消消乐游戏, 关卡丰富,很好玩 下载地址:点击下载

  9. Codeforces Beta Round #49 (Div. 2)

    Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A #include<bits/stdc++.h> ...

  10. python之格式化输出

    字符串格式化有两种方式,%和format 先介绍下%号的方法 #%s的语法结构,叫做占位符,就是先占一个位置,然后我们用真实的要显示的数据替换占位符即可#最简单的用法就是下面的方式,其实%s还有其他的 ...