HttpURLConnection請求返回資料部分亂碼問題
阿新 • • 發佈:2019-01-09
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();
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();