将调用编码改为UTF-8
示例代码:
在调用前,将编码设置为UTF-8:
URLConnection urlc = url.openConnection(); urlc.setRequestProperty("Content-Type", "application/json; charset=utf-8"); urlc.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(urlc.getOutputStream(), "UTF-8"); writer.write(requestData); writer.flush(); writer.close();
在接收响应后,将编码设置为UTF-8:
String response = IOUtils.toString(inputStream, "UTF-8");