I’ve read through the other excellent stack overflow articles and tried a lot of them and variations on them but must be making some basic error time and time again? The page I’m posting to works but when I run my java program I just get an empty set on the mySQL database that the data is being posted to. The direct URL that works would be:
http://myURL.co.uk/enteremail.php?email=value
the code
String data = URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
URL url = new URL("http://myURL.co.uk/enteremail.php");
URLConnection conn = url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
wr.close();
I know that there are much better ways of doing this using java but I have to use this way as its a bit of a workaround for another problem.
TIA
I’d still like to know what was up with my original code, but because what I wanted to do was so simple I’ve just cut a corner and done this which works for sending the post request to a php page but may not be the solution for anything else:
Hopefully of some help to someone else down the line, KISS