- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我已经使用适用于 Android (2.0.15) 的 ReSTLet 框架编写了一个 Android Web 服务客户端,并且我还编写了 Web 服务后端(同样使用 ReSTLet 2.0.15 JEE),它已上传到 AWS Elastic Beanstalk (因此客户端调用将采用“http://my_web_service.elasticbeanstalk.com/this/is/my/request”的形式)。在 HTTP 上一切正常,所以现在我想用 HTTPS 替换它,但事实证明这比我最初想象的要困难。
我从 Comodo 创建了一个试用 SSL 证书,我在其中将我拥有的域声明为 CNAME(不幸的是,我无法将运行 AWS 负载均衡器的 elasticbeanstalk.com 子域声明为证书主机名)。此证书已上传到我的 AWS 实例,它似乎正在成功运行(通过 Web 浏览器测试,在我接受浏览器上的证书后,几个 https 调用成功通过)。我唯一不喜欢这个证书的事实是,我收到一个警告,这可能是一个无效的证书,因为声明的主机名(我的域)和证书正在运行的实际主机名(elasticbeanstalk.com)不符合。
在我的客户端中,我使用的是 apache http 客户端(已在 claspath 上加载了 org.apache.httpclient.jar),这就是我创建每次调用时使用的客户端资源的方式,这很简单:
ClientResource resource = new ClientResource(resourceUri);
Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));
resourceUri
格式为“
https://my_web_service.elasticbeanstalk.com/this/is/my/request”,这是工作 HTTP 案例和非工作 HTTPS 案例之间的唯一区别。
|Time | 192.168.2.111 |
| | | 54.245.249.149 |
|14.769 | 65430 > https [SYN] |TCP: 65430 > https [SYN] Seq=0 Win=65535 Len=0 MSS=1460 WS=16 TSval=3906214190 TSecr=0 SACK_PERM=1
| |(65430) ------------------> (443) |
|15.026 | https > 65430 [SYN, |TCP: https > 65430 [SYN, ACK] Seq=0 Ack=1 Win=14480 Len=0 MSS=1452 SACK_PERM=1 TSval=758478734 TSecr=3906214190 WS=256
| |(65430) <------------------ (443) |
|15.027 | 65430 > https [ACK] |TCP: 65430 > https [ACK] Seq=1 Ack=1 Win=132480 Len=0 TSval=3906214442 TSecr=758478734
| |(65430) ------------------> (443) |
|15.034 | Client Hello |TLSv1: Client Hello
| |(65430) ------------------> (443) |
|15.289 | https > 65430 [ACK] |TCP: https > 65430 [ACK] Seq=1 Ack=124 Win=14592 Len=0 TSval=758478799 TSecr=3906214448
| |(65430) <------------------ (443) |
|15.291 | Server Hello, Certi |TLSv1: Server Hello, Certificate, Server Hello Done
| |(65430) <------------------ (443) |
|15.291 | 65430 > https [ACK] |TCP: 65430 > https [ACK] Seq=124 Ack=1386 Win=131088 Len=0 TSval=3906214696 TSecr=758478799
| |(65430) ------------------> (443) |
|17.207 | Client Key Exchange |TLSv1: Client Key Exchange, Change Cipher Spec, Encrypted Handshake Message
| |(65430) ------------------> (443) |
|17.505 | Encrypted Handshake |TLSv1: Encrypted Handshake Message, Change Cipher Spec, Encrypted Handshake Message
| |(65430) <------------------ (443) |
|17.505 | Client Hello |TLSv1: Client Hello
| |(65430) ------------------> (443) |
|17.507 | 65430 > https [FIN, |TCP: 65430 > https [FIN, ACK] Seq=557 Ack=1636 Win=130832 Len=0 TSval=3906216837 TSecr=758479353
| |(65430) ------------------> (443) |
|17.776 | Encrypted Alert |TLSv1: Encrypted Alert
| |(65430) <------------------ (443) |
|17.776 | 65430 > https [RST] |TCP: 65430 > https [RST] Seq=557 Win=0 Len=0
| |(65430) ------------------> (443) |
|17.777 | Encrypted Alert |TLSv1: Encrypted Alert
| |(65430) <------------------ (443) |
|17.777 | https > 65430 [FIN, |TCP: https > 65430 [FIN, ACK] Seq=1682 Ack=557 Win=15616 Len=0 TSval=758479421 TSecr=3906216836
| |(65430) <------------------ (443) |
|17.777 | https > 65430 [ACK] |TCP: https > 65430 [ACK] Seq=1683 Ack=558 Win=15616 Len=0 TSval=758479421 TSecr=3906216837
| |(65430) <------------------ (443) |
|17.777 | 65430 > https [RST] |TCP: 65430 > https [RST] Seq=557 Win=0 Len=0
| |(65430) ------------------> (443) |
|17.777 | 65430 > https [RST] |TCP: 65430 > https [RST] Seq=557 Win=0 Len=0
| |(65430) ------------------> (443) |
|17.777 | 65430 > https [RST] |TCP: 65430 > https [RST] Seq=558 Win=0 Len=0
| |(65430) ------------------> (443) |
public static ClientResource createClientResource(String resourceUri) {
Reference reference = new Reference(resourceUri);
System.setProperty("ssl.TrustManagerFactory.algorithm",javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm());
org.restlet.Context context = new org.restlet.Context();
context.getAttributes().put("hostnameVerifier", new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
ClientResource resource = new ClientResource(context, reference);
Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));
Engine.getInstance().getRegisteredConverters().add(0, new JacksonConverter());
resource.release();
return resource;
}
最佳答案
我终于设法解决了这个问题。
在检查“响应”对象,更具体地说是响应状态之后,这是错误引发的异常:
Communication Error (1001) - The connector failed to complete the communication with the server
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
关于Android 客户端 - ReSTLet 2.0.15 - 无法使用 HTTPS/SSL 连接 - 可恢复错误 1001,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16345088/
我试图允许用户使用Devise的可恢复选项重置密码。这似乎对我不起作用。 我扩展了Devise::PasswordsController,使其不使用应用程序布局。 class PasswordsCon
最近两周,我没有发布应用更新,却开始收到一堆数据库损坏的报告。下面是堆栈跟踪。 Android打不开数据库,我电脑上的sqlite-manager程序也打不开。但是,firefox 的 SQLite
我一直在试验 resumable.js,我对它在笔记本电脑上的内置 node.js 服务器的性能感到非常满意。但是,当我将它部署到 heroku 或 nodejitsu 并收到此错误时,它会在超过 1
我正在使用 YouTube Data API v3 从我的 Android 应用程序将视频上传到我的 YouTube 帐户.上传过程完美无缺。我需要的是,如果我的上传被中断(例如,由于互联网连接)
我是一名优秀的程序员,十分优秀!