可能重复:
How do I accept a self-signed certificate with a Java HttpsURLConnection?
我已经设置了HTTP GET。
代码如下:
public class GetMethodEx {
public String getInternetData() throws Exception{
BufferedReader in = null;
String data = null;
try
{
HttpClient client = new DefaultHttpClient();
URI website = new URI("http://www.google.com");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) !=null){
sb.append(l + nl);
}
in.close();
data = sb.toString();
return data;
} finally{
if (in != null){
try{
in.close();
return data;
}catch (Exception e){
e.printStackTrace();
}
}
}
}
}
该代码允许我检索任何http网站,我假设签名证书。
但是,当我尝试从自签名服务器检索请求时。我没有回复。
答案 0 :(得分:0)
要恢复,您可以使用这两个答案中的一个,这将解决您的问题:
很容易解决您的问题。