发送http post请求返回的数据中文乱码,在网上搜了一下,找到一个相关的资源,结果发现用不了,最后自己试着改了一下,终于解决了这个乱码的问题。
public static String post(String url, String charset, Map params) throws IOException {
HttpURLConnection conn = null;
OutputStreamWriter out = null;
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader reader = null;
StringBuffer result = new StringBuffer();
try {
conn = (HttpURLConnection) new URL(url).openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Accept-Charset", charset);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
out = new OutputStreamWriter(conn.getOutputStrea