execute(HttpPost post)
메서드를 사용하여 Apache의 DefaultHttpClient()
을 사용하여 http POST를 수행합니다. 이 웹 사이트에 로그온합니다. 그런 다음 동일한 클라이언트를 사용하여 HttpGet
을 만들고 싶습니다. 그러나 내가 할 때, 나는 예외 얻을 : 스레드 "주요"java.lang.IllegalStateException에서POST 후 HttpClient를 사용하여 GET을 실행할 때 예외가 발생했습니다.
예외 : SingleClientConnManager의 잘못된 사용 : 아직 할당 연결합니다.
왜 이런 일이 발생하는지 확신 할 수 없습니다. 어떤 도움을 주시면 감사하겠습니다.
public static void main(String[] args) throws Exception {
// prepare post method
HttpPost post = new HttpPost("http://epaper02.niedersachsen.com/epaper/index_GT_neu.html");
// add parameters to the post method
List <NameValuePair> parameters = new ArrayList <NameValuePair>();
parameters.add(new BasicNameValuePair("username", "test"));
parameters.add(new BasicNameValuePair("passwort", "test"));
UrlEncodedFormEntity sendentity = new UrlEncodedFormEntity(parameters, HTTP.UTF_8);
post.setEntity(sendentity);
// create the client and execute the post method
HttpClient client = new DefaultHttpClient();
HttpResponse postResponse = client.execute(post);
//Use same client to make GET (This is where exception occurs)
HttpGet httpget = new HttpGet(PDF_URL);
HttpContext context = new BasicHttpContext();
HttpResponse getResponse = client.execute(httpget, context);
// retrieve the output and display it in console
System.out.print(convertInputStreamToString(postResponse.getEntity().getContent()));
client.getConnectionManager().shutdown();
}
참조 : http://stackoverflow.com/questions/4612573/exception-using-httprequest-execute-invalid-use-of-singleclientconnmanager-co –