【发布时间】:2020-11-28 07:12:21
【问题描述】:
作为一个 restful 客户端,我可以使用 Postman 软件成功连接到服务器,无需任何认证或安全设置。 (我从服务器收到正确的响应) 但是当我使用java程序调用它时,它会在下面抛出异常:
javax.net.ssl.SSLHandshakeException:找不到与 IP 地址 192.168.12.125 匹配的主题备用名称
我还查看了这个 link 并没有解决我的问题。
这是我使用的java代码:
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import java.io.Serializable;
public class CallService implements Serializable {
private String uri = "https://192.168.12.125:443/ssdpn";
private Client client;
private WebResource webResource;
public void sendRequest(String input) {
try {
client = Client.create();
webResource = client.resource(uri);
String requestBody = prepareJSONFormatRequest(input);
ClientResponse response =
webResource.path("/Service205")
.header("trackId", "1001")
.header("serviceId", "Service205")
.post(ClientResponse.class, requestBody);
String result = response.getEntity(String.class);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
private String prepareJSONFormatRequest(String input) {
StringBuilder request = new StringBuilder();
request.append("{ ").append("\"SerialNumber\":\"").append(input).append("\" }");
return request.toString();
}
}
在 java 程序中,我也没有使用证书(就像我在 Postman 调用中所做的那样)。 谁能帮我找出问题出在哪里?
【问题讨论】:
-
您的证书文件中是否定义了 san 标签?
-
不,我不使用这样的标签!
-
你应该用这个ip添加它
标签: java rest rest-client