JavaでHttpComponentsを使用して、ログイン情報をWebサイトにPOSTしています。ログイン後、返されたWebページに応じて、より多くのPOSTデータを送信したいと思います。POSTデータを送信した結果としてサーバーが返すhtml/webページを実際に印刷または表示する方法がわかりません(おそらく、私が探しているのは応答本文ですか?)。
すべてのチュートリアルは、ヘッダー情報またはサーバーコードを表示する方法のみを示しているようです。それはおそらく私が見逃している単純なものだと思います。このプロセスをよく理解していない可能性があります。
これまでの私のコード:
public class httpposter {
public static void main(String[] args) throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://hroch486.icpf.cas.cz/cgi-bin/echo.pl");
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("username", "vip"));
nvps.add(new BasicNameValuePair("password", "secret"));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
HttpResponse response2 = httpclient.execute(httpPost);
try {
System.out.println(response2);
HttpEntity entity2 = response2.getEntity();
// do something useful with the response body
// and ensure it is fully consumed
EntityUtils.consume(entity2);
} finally {
httpPost.releaseConnection(); }} }