我有 HttpClient 4.1。请看以下程序:
import org.apache.http.client.methods.*;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
public class SysCommands {
public static void main(String [] args){
try{
HttpClient c = new DefaultHttpClient();
System.out.println("Initial part");
HttpGet method = new HttpGet("http://www.google.com");
HttpResponse resp = c.execute(method);
System.out.println("Method executed");
String s = "";
resp.getHeaders(s);
System.out.println("headers are "+s);
BufferedReader rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}catch(Exception e){
System.out.println(e);
}
}
}
当我运行它时,我得到org.apache.http.client.ClientProtocolException
. 有什么问题?