我不熟悉 API(官方和非官方),我正在使用一个名为JavaSnap的 API 。我一直在搞乱示例代码的一个非常基本的实现,但一直遇到错误。这是非常基本的代码:
Snapchat snapchat = Snapchat.login("xxxx", "xxxxx");
首先,我遇到了大量 ClassNotFound 错误,不得不继续下载 apache 模块(commons、httpcomponents 等)以允许程序运行,但是作为类文件,这意味着我无法一次看到我需要下载哪些模块. 因此,如果有人想告诉我我做某事有多么错误,请随意。
无论如何,现在已经清除了所有 ClassNotFound 异常(我希望)我得到以下异常:
com.mashape.unirest.http.exceptions.UnirestException: javax.net.ssl.SSLPeerUnverifiedException: Host name 'feelinsonice-hrd.appspot.com' does not match the certificate subject provided by the peer (CN=*.appspot.com, O=Google Inc, L=Mountain View, ST=California, C=US)
at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:146)
at com.mashape.unirest.request.BaseRequest.asJson(BaseRequest.java:68)
at com.habosa.javasnap.Snapchat.requestJson(Snapchat.java:953)
at com.habosa.javasnap.Snapchat.login(Snapchat.java:160)
at Tester.go(Tester.java:21)
据我了解,这是因为我需要启用信任所有证书,但是要做到这一点,我相信我需要将 HostNameVerifiers 与 SSLSocketFactorys 一起使用,但我不能真正开始解决这个问题,因为我只有源对于 JavaSnap API,并在堆栈中跟踪错误,我可以编辑的最新方法是:
private static HttpResponse<JsonNode> requestJson(String path, Map<String, Object> params, File file) throws UnirestException {
MultipartBody req = prepareRequest(path, params, file);
// Execute and return response as JSON
HttpResponse<JsonNode> resp = req.asJson();
// Record
lastRequestPath = path;
lastResponse = resp;
lastResponseBodyClass = JsonNode.class;
return resp;
我的问题是,我的想法真的是正确的吗?
如果我是如何实现消除此错误/信任证书的目标?如果我不是那么实际上是什么问题?
非常感谢