我目前正在尝试使用他们当前的API v3上传到imgur,但我不断收到错误
error: javax.net.ssl.SSLException: hostname in certificate didn’t match: api.imgur.com != imgur.com OR imgur.com
错误是非常自我解释的,所以我想我会尝试使用http而不是我得到错误代码400与imgur.我不确定这是否意味着我尝试上传是错误的还是Imgur不喜欢SSL连接.
下面是我连接到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
我希望有人可以帮助找到上述代码中的错误或解释如何解决当前的HTTPS问题,谢谢.
最佳答案
看起来证书中的域名与您正在访问的域名不匹配,因此SSL按预期失败.您可以告诉HttpClient忽略证书问题并建立连接.有关详细信息,请参见此stackoverflow answer.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。