小编Ste*_*nTo的帖子

如何在Square MockWebServer中使用SSL?

我尝试在Square的MockWebServer上启用SSL,以模拟我的Android App中的所有Web服务调用.我想启用SSL以获得与真实条件相同的错误.我不想为测试禁用SSL或实现SSL忽略的HTTPClient.

在每个请求我得到这个javax.net.ssl.SSLPeerUnverifiedExceptionecxeption:

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://localhost:42451/api/blabla": No peer certificate; nested exception is javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
Run Code Online (Sandbox Code Playgroud)

我似乎需要为MockWebServer设置证书.但我不知道怎么......

这是我尝试启用SSL的方式:

SSLContext sslContext = new SslContextBuilder(InetAddress.getLocalHost().getHostName()).build();
server.useHttps(sslContext.getSocketFactory(), true);
Run Code Online (Sandbox Code Playgroud)

要么:

SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, null, null);
server.useHttps(sslContext.getSocketFactory(), false);
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?

ssl https android square mockwebserver

7
推荐指数
2
解决办法
2645
查看次数

标签 统计

android ×1

https ×1

mockwebserver ×1

square ×1

ssl ×1