Code:
import org.apache.http.client.*;
public class Main {
try
{
HttpClient client = new HttpClient();
GetMethod getMethod1 = new GetMethod("http://example.org/geheim.php");
client.executeMethod(getMethod1);
System.out.println("Aufruf ohne Login —————–");
System.out.println(getMethod1.getResponseBodyAsString());
System.out.println("———————————–");
PostMethod postMethod1 = new PostMethod("http://example.org/login.php");
postMethod1.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
postMethod1.addParameter("name", "stefan");
postMethod1.addParameter("pass", "geheim");
client.executeMethod(postMethod1);
System.out.println("Login —————————–");
System.out.println(postMethod1.getResponseBodyAsString());
System.out.println("———————————–");
client.executeMethod(getMethod1);
System.out.println("Aufruf nach Login —————–");
System.out.println(getMethod1.getResponseBodyAsString());
System.out.println("———————————–");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Zuletzt bearbeitet: