J
Jonathan
Hi,
I'm trying to post (using POST method) form-like data (Let's say
parameter name = X; Value=ABC) from a Java program to a server, but it
doesn't seem to work. Any help would be greatly appreciated. This is
the code I'm using :
String data = "X=ABC";
URL u = new URL(url);
URLConnection connection = u.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
connection.setRequestProperty("Content-type","application/x-www-form-urlencoded");
((HttpURLConnection) connection).setRequestMethod("POST");
connection.setRequestProperty("Content-Length", "" + data.length());
BufferedWriter out = new BufferedWriter(new
OutputStreamWriter(connection.getOutputStream()));
out.write(data);
out.flush();
out.close();
connection.connect();
Thanks for your help!
Jonathan
I'm trying to post (using POST method) form-like data (Let's say
parameter name = X; Value=ABC) from a Java program to a server, but it
doesn't seem to work. Any help would be greatly appreciated. This is
the code I'm using :
String data = "X=ABC";
URL u = new URL(url);
URLConnection connection = u.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setAllowUserInteraction(false);
connection.setRequestProperty("Content-type","application/x-www-form-urlencoded");
((HttpURLConnection) connection).setRequestMethod("POST");
connection.setRequestProperty("Content-Length", "" + data.length());
BufferedWriter out = new BufferedWriter(new
OutputStreamWriter(connection.getOutputStream()));
out.write(data);
out.flush();
out.close();
connection.connect();
Thanks for your help!
Jonathan