| | |
| | | |
| | | /** |
| | | * 发送文件上传请求(支持自定义文件名) |
| | | * 支持HTTP和HTTPS,HTTPS会自动忽略SSL证书验证 |
| | | * |
| | | * @param url 请求URL |
| | | * @param params 请求参数(包含文件流) |
| | |
| | | // 创建连接 |
| | | URL requestUrl = new URL(url); |
| | | connection = (HttpURLConnection) requestUrl.openConnection(); |
| | | |
| | | // 如果是HTTPS请求,配置SSL信任所有证书 |
| | | if (connection instanceof HttpsURLConnection) { |
| | | HttpsURLConnection httpsConnection = (HttpsURLConnection) connection; |
| | | SSLContext sc = SSLContext.getInstance("TLS"); |
| | | sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new java.security.SecureRandom()); |
| | | httpsConnection.setSSLSocketFactory(sc.getSocketFactory()); |
| | | httpsConnection.setHostnameVerifier(new TrustAnyHostnameVerifier()); |
| | | log.info("配置HTTPS连接,忽略SSL证书验证"); |
| | | } |
| | | |
| | | |
| | | // 设置请求属性 |
| | | connection.setRequestMethod("POST"); |
| | | connection.setDoOutput(true); |