我开发了一个明确有效的HTTP GET方法.
public class GetMethodEx {
public String getInternetData() throws Exception{
new TrustAllManager();
new TrustAllSSLSocketFactory();
BufferedReader in = null;
String data = null;
try
{
HttpClient client = new DefaultHttpClient();
URI website = new URI("https://server.com:8443/Timesheets/ping");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
response.getStatusLine().getStatusCode();
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;
} …
Run Code Online (Sandbox Code Playgroud)