| | |
| | | import javax.net.ssl.TrustManager; |
| | | import javax.net.ssl.X509TrustManager; |
| | | |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.constant.Constants; |
| | |
| | | conn.setRequestProperty("connection", "Keep-Alive"); |
| | | conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
| | | conn.setRequestProperty("Accept-Charset", "utf-8"); |
| | | conn.setRequestProperty("Charsert", "UTF-8"); |
| | | conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); |
| | | conn.setDoOutput(true); |
| | | conn.setDoInput(true); |
| | |
| | | } |
| | | } |
| | | out = new PrintWriter(new OutputStreamWriter(conn.getOutputStream(), StandardCharsets.UTF_8)); |
| | | log.error("---------param发送的数据为:{}",param); |
| | | log.info("---------param发送的数据为:{}",param); |
| | | out.print(param); |
| | | out.flush(); |
| | | in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); |
| | |
| | | } |
| | | } |
| | | |
| | | log.error("发送参数:{}", param); |
| | | log.info("发送参数:{}", param); |
| | | try (OutputStream os = conn.getOutputStream()) { |
| | | byte[] input = param.getBytes(StandardCharsets.UTF_8); |
| | | os.write(input, 0, input.length); |
| | |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | public static String sendPost(String url){ |
| | | HttpPost post = new HttpPost(url); |
| | | CloseableHttpClient client = HttpClients.createDefault(); |
| | | //启动执行请求,并获得返回值 |
| | | CloseableHttpResponse execute = null; |
| | | try { |
| | | execute = client.execute(post); |
| | | HttpEntity entity = execute.getEntity(); |
| | | //把实体对象转换为string |
| | | return EntityUtils.toString(entity, "UTF-8"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return "调用失败"; |
| | | } |
| | | |
| | | } |