- System.setProperty("javax.net.ssl.keyStore","c:\\tomcat.jks");
- System.setProperty("javax.net.ssl.keyStorePassword","12345678");
- System.setProperty("javax.net.ssl.trustStore","c:\\tomcat.jks");
- System.setProperty("javax.net.ssl.trustStorePassword","12345678");
- String urlResouce = "https://localhost:8443/cloud-storeage-boss/cai:images:public/11汉字.jpg"; // create URL
- File localFile = new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg");
- try{
- HttpsURLConnection urlConnection =
- (HttpsURLConnection) (new URL(urlResouce)).openConnection();
- urlConnection.setRequestProperty("Charset", "UTF-8");
- urlConnection.setDoInput(true);
- urlConnection.setDoOutput(true);
- urlConnection.setRequestMethod("PUT");
- OutputStream urlOutputStream = urlConnection.getOutputStream();
- FileInputStream fileInputStream = new FileInputStream(localFile);
- IOUtils.copy(fileInputStream, urlOutputStream);
- fileInputStream.close();
- urlOutputStream.close();
- System.out.println(urlConnection.getResponseCode());
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
关键就是系统参数的设置,将证书设置到系统中去,如果已经将安全证书安装到JDK那就很easy了