I am using Apache DefaultHttpClient()with a method execute(HttpPost post)to do http POST. With this I went to the site. Then I want to use the same client to do HttpGet. But when I do this, I get an exception:
Exception in thread "main" java.lang.IllegalStateException: Invalid use of SingleClientConnManager: connection is still highlighted.
I am not sure why this is happening. Any help would be appreciated.
public static void main(String[] args) throws Exception {
HttpPost post = new HttpPost("http://epaper02.niedersachsen.com/epaper/index_GT_neu.html");
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);
HttpClient client = new DefaultHttpClient();
HttpResponse postResponse = client.execute(post);
HttpGet httpget = new HttpGet(PDF_URL);
HttpContext context = new BasicHttpContext();
HttpResponse getResponse = client.execute(httpget, context);
System.out.print(convertInputStreamToString(postResponse.getEntity().getContent()));
client.getConnectionManager().shutdown();
}
source
share