URL Connection Problem
Hi all,
I want to send applet parameters to web server using URL.And got many links explaining that.
I tried with following code.But gives IOException and as newbie I am confused how to run this so I can send data to web server.
try{
URLurl;
URLConnectionurlConn;
DataOutputStreamdos;
DataInputStreamdis;
url =new URL("http://webserver.our-intranet.com/cgi-bin/AddToDoItem");
urlConn = url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
urlConn.setRequestProperty ("Content-Type","application/x-www-form-urlencoded");
dos =new DataOutputStream (urlConn.getOutputStream());
// String message = "NEW_ITEM=" + URLEncoder.encode(addTextField.getText());
String message ="NEW_ITEM=" + URLEncoder.encode("Hello");
dos.writeBytes(message);
dos.flush();
dos.close();
// the server responds by saying
// "SUCCESS" or "FAILURE"
dis =new DataInputStream(urlConn.getInputStream());
String s = dis.readLine();
dis.close();
if (s.equals("SUCCESS")){
// jTextField1.add
// addTextField.setText("");
System.out.println("Done");
}else{
System.out.println("Not Done");
}
}// end of "try"
catch (MalformedURLException mue){
System.out.println("mue error");
}
catch (IOException ioe){
System.out.println("IO Exception");
}
Plz help!!
Regards,
Palak

