1. 程式人生 > >HttpURLConnection請求返回資料部分亂碼問題

HttpURLConnection請求返回資料部分亂碼問題

public static String sendPostNew(String url, String param,String authorization) {
String result = "";
try {
URL httpurl = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection) httpurl
.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.addRequestProperty("Authorization", "Bearer " + authorization);
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

PrintWriter out = new PrintWriter(new OutputStreamWriter(
httpConn.getOutputStream(), "utf-8"));

out.print(param);
out.flush();
out.close();


int code=httpConn.getResponseCode();