URL url = new URL(add_url); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); // 传json时,需要这个,不传json,不需要 connection.setRequestProperty("Content-Type", "application/json"); connection.connect(); // DataOutputStream out = new DataOutputStream(connection.getOutputStream()); OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); System.out.println(s5); out.write(s5); out.flush(); out.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String lines; StringBuffer sbf = new StringBuffer(); while ((lines = reader.readLine()) != null) { lines = new String(lines.getBytes(), "utf-8"); sbf.append(lines); } System.out.println(sbf); reader.close(); // 断开连接 connection.disconnect();