public void doPost() throws Exception {
try {
// Construct data
String data = URLEncoder.encode("j_username", "UTF-8") + "=" + URLEncoder.encode("test", "UTF-8");
data += "&" + URLEncoder.encode("j_password", "UTF-8") + "=" + URLEncoder.encode("test", "UTF-8");
// Send data
URL url = new URL("/specialpages/script.jsp");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
//// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
wr.close();
rd.close();
} catch (Exception e) {
}
}
Tuesday, June 23, 2009
Java HTTP POST Request
Labels:
Java,
Programming
Subscribe to:
Post Comments (Atom)


0 comments:
Post a Comment