Trying to register a user into the database.
This code works:
try {
URL url = new URL("http://www.jacksteel.co.uk/Comp4/registeruser.php?" + getQuery(userData));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(getQuery(userData));
Log.d("myTag", getQuery(userData));
writer.flush();
writer.close();
os.close();
Log.d("myTag",conn.getInputStream().toString());
conn.connect();
} catch (Exception e) {
e.printStackTrace();
}
However this code does not:
try {
URL url = new URL("http://www.jacksteel.co.uk/Comp4/registeruser.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(getQuery(userData));
Log.d("myTag", getQuery(userData));
writer.flush();
writer.close();
os.close();
Log.d("myTag",conn.getInputStream().toString());
conn.connect();
} catch (Exception e) {
e.printStackTrace();
}
The only difference being that I concatenated the result of getQuery() onto the end of the URL, which suggests that the HTTP post is not working, I got the code fore the Post from here I already have the data in a nameValuePair list called 'userData'
So, my question is why does it not work without appending getQuery(userData)
to the URL, and can I make it work?