HttpClient 4.1이 있습니다. 다음 프로그램을 살펴보십시오.간단한 java HttpClient 프로그램이 작동하지 않습니다.
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
이됩니다. 무엇이 잘못 될 수 있습니까?
정확히 예외가 발생합니까? 귀하의 코드는 나를 위해 작동합니다. 또한 Runtime/Process 코드가 질문에 어떻게 적용되는지, 제거하지 않으면 제거하십시오. –
전체 스택 추적을 얻으려면 System.out.println (e) 대신 e.printStackTrace()를 시도하십시오. 또한 reps.getHeaders (s)는 배열을 반환하고 s는 변경되지 않습니다. 실행 직후 –
google.com 전용입니다. 나는 www.affinity.com을 시도해 보았다. 어떻게! !! – Shades88