tôi đang cố gắng để tải lên imgur sử dụng v3 API hiện tại của họ, tuy nhiên tôi tiếp tục nhận được lỗitải lên Imgur v3 sử dụng https Java lỗi
error: javax.net.ssl.SSLException: hostname in certificate didn't match: api.imgur.com != imgur.com OR imgur.com
Các lỗi được khá tự explaintory vì vậy tôi nghĩ tôi sẽ thử sử dụng http thay vào đó nhưng tôi nhận được mã lỗi 400 với imgur. Tôi không chắc chắn nếu điều này có nghĩa là cách tôi đang cố gắng tải lên là sai hoặc nếu Imgur không thích kết nối SSL.
Dưới đây là mô-đun của tôi mã kết nối với Imgur:
public String Imgur (String imageDir, String clientID) {
//create needed strings
String address = "https://api.imgur.com/3/image";
//Create HTTPClient and post
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(address);
//create base64 image
BufferedImage image = null;
File file = new File(imageDir);
try {
//read image
image = ImageIO.read(file);
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
ImageIO.write(image, "png", byteArray);
byte[] byteImage = byteArray.toByteArray();
String dataImage = new Base64().encodeAsString(byteImage);
//add header
post.addHeader("Authorization", "Client-ID" + clientID);
//add image
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("image", dataImage));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//execute
HttpResponse response = client.execute(post);
//read response
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String all = null;
//loop through response
while (rd.readLine() != null) {
all = all + " : " + rd.readLine();
}
return all;
}
catch (Exception e){
return "error: " + e.toString();
}
}
Tôi hy vọng ai đó có thể giúp đỡ trong việc tìm kiếm hoặc các lỗi trong đoạn mã trên hoặc giải thích làm thế nào để khắc phục vấn đề HTTPS hiện tại, cảm ơn.
Bạn đã bao giờ tìm thấy câu trả lời cho điều này chưa? Tôi thực sự cần phải tìm ra cách để làm điều này, và việc tạo ra SSLFactory của riêng tôi cũng không hoạt động. –