尝试在 Java 中将证书添加到我的 Post 方法中



嗨,我试图将 crt 和密钥文件添加到我的 post 方法中,因为 im 使用 SSL 连接以 https 协议连接到服务器

我不知道如何将crt和密钥以及我的服务器密码添加到我的请求中。

而且我在设置/客户端证书区域中的邮递员中使用这些证书

public static  GetAPI(String query_url) {
int ResponseCode = -1;
try {
URL url = new URL(query_url);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
con.setConnectTimeout(5000);
// con.setDoOutput(true);
// con.setDoInput(true);
ResponseCode = con.getResponseCode();
InputStream in = new BufferedInputStream(con.getInputStream());
String result = IOUtils.toString(in, "UTF-8");
// System.out.println(con.getResponseCode());
// System.out.println(result);
// System.out.println("result after Reading JSON Response");
// JSONObject myResponse = new JSONObject(result);
// System.out.println("jsonrpc- "+myResponse.getString("jsonrpc"));
in.close();
con.disconnect();
return 
} catch (Exception e) {
System.out.println(e);

}

如果我正确理解了您的情况,我认为您需要将服务器证书添加到您的 jre 中。 看看这篇文章。

相关内容

最新更新