PDA

Visualizza la versione completa : POST HTTP in java


thenanny1983
08-04-2005, 16:55
POTETE SCRIVERMI PER FAVORE IL CODICE JAVA DEL METODO POST HTTP ?

AIUTATEMI! :oVVoVe:
Grazie mille!


:dh:

V1RuZ
09-04-2005, 12:03
da java almanac:


try {
// Construct data
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");

// Send data
URL url = new URL("http://hostname:80/cgi");
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) {
// Process line...
}
wr.close();
rd.close();
} catch (Exception e) {
}


evita di strillare x...

Loading