How can I get rid of the casting?
HttpURLConnection connection = (HttpURLConnection) email.openConnection();
// email is the URL of the CGI script
connection.setRequestMethod("POST");
connection.setDoOutput(true);
PrintStream out = new PrintStream(connection.getOutputStream());
out.println("Name=datorn");
out.close();
} catch(MalformedURLException mue) {
showStatus("Illegal URL: " + mue);
} catch(IOException ioe) {
showStatus("IOException: " + ioe);
} catch(Exception e) {
showStatus("Error: " + e);
}
PS. I've tested URLConnection but it didn't seem to work either DS.
Best regards, Erik
See NetUtil in my utilities package at
http://www.pobox.com/~skeet/java/skeetutil/ for an example of posting in
Java, which you can modify to do what you need to. I've always found
that the order in which you connect etc is quite fragile and badly
documented.
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
see http://www.bruececkel.com for Bruce's book Thinking in Java, which
explains how to do this in detail.
Pete
uc.setRequestProperty("Content-type","application/x-www-form-urlencoded");
uc.setRequestProperty("Content-length",""+data.length());
DataOutputStream dos=new DataOutputStream(uc.getOutputStream());
dos.writeBytes(data);
dos.close();
DataInputStream dis=new DataInputStream(uc.getInputStream());
String line;
while((line=dis.readLine()) != null){
ta.appendText(line);
ta.appendText("\n");
}
dis.close();
}
catch(Exception e){
ta.appendText("post error");
e.printStackTrace();
}
}
Erik Kjellson <erik.k...@home.se> a écrit dans le message :
ln5Z6.14146$vR1....@nntpserver.swip.net...