| | |
| | | public static String doPost(String httpUrl,String requestBody) { |
| | | HttpURLConnection connection = null; |
| | | InputStream inputStream = null; |
| | | OutputStream outputStream =null; |
| | | BufferedReader bufferedReader = null; |
| | | String result = null;// 返回结果字符串 |
| | | try { |
| | |
| | | |
| | | //请求体 |
| | | connection.setDoOutput(true); |
| | | OutputStream outputStream = connection.getOutputStream(); |
| | | outputStream = connection.getOutputStream(); |
| | | OutputStreamWriter osw = new OutputStreamWriter(outputStream,"UTF-8"); |
| | | |
| | | osw.write(requestBody); |
| | | osw.flush(); |
| | | outputStream.close(); |
| | | // 发送请求 |
| | | connection.connect(); |
| | | // 通过connection连接,获取输入流 |
| | |
| | | if (connection != null) { |
| | | connection.disconnect();// 关闭远程连接 |
| | | } |
| | | if (null != outputStream) { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |