| | |
| | | public class BroadcastPostUtils { |
| | | |
| | | |
| | | public static String Post (String json,String URL, String charset) { |
| | | public static String Post(String json, String URL, String charset) { |
| | | CloseableHttpClient client = HttpClients.createDefault(); |
| | | HttpPost post = new HttpPost(URL); |
| | | post.setHeader("Content-Type", "application/json"); |
| | |
| | | HttpResponse httpResponse = client.execute(post); |
| | | InputStream inStream = httpResponse.getEntity().getContent(); |
| | | |
| | | result = streamToString(inStream,charset); |
| | | result = streamToString(inStream, charset); |
| | | |
| | | inStream.close(); |
| | | } catch (Exception e) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * m 1 1 1 |
| | | * f 1 1 1 |
| | | * y 1 |
| | | * @param in |
| | | * @param encoding |
| | | * @return |
| | | */ |
| | | |
| | | |
| | | public static String streamToString(InputStream in, String encoding){ |
| | | public static String streamToString(InputStream in, String encoding) { |
| | | // 将流转换为字符串 |
| | | try { |
| | | StringBuffer sb = new StringBuffer(); |
| | | byte[] b = new byte[1024]; |
| | | for (int n; (n = in.read(b)) != -1;) { |
| | | for (int n; (n = in.read(b)) != -1; ) { |
| | | sb.append(new String(b, 0, n, encoding)); |
| | | } |
| | | return sb.toString(); |
| | | } catch (IOException e) { |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("提取 requestBody 异常", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public static String taskPostEncoding (String json, String URL) { |
| | | public static String taskPostEncoding(String json, String URL) { |
| | | CloseableHttpClient client = HttpClients.createDefault(); |
| | | HttpPost post = new HttpPost(URL); |
| | | post.setHeader("Content-Type", "application/json"); |
| | |
| | | HttpResponse httpResponse = client.execute(post); |
| | | InputStream inStream = httpResponse.getEntity().getContent(); |
| | | |
| | | result = streamToString(inStream,"utf-8"); |
| | | result = streamToString(inStream, "utf-8"); |
| | | |
| | | |
| | | inStream.close(); |