I've run into a bit of a deadend and need a bit of help (please)!
I'm very new to Android Dev (and to coding in general). Basically I need to POST XML data to a URL using HttpURLConnection but can't get it to work. I've got my app reading and pasrsing XML data from a GET request but finding the POST part difficult.
I've looked at creating a NameValuePair array but not sure how to do this with the XML structure I am needing to post.
The XML data will look like this:
<Sheet>
<Job>jobNumber</Job>
<Task>taskNumber</Task>
<UserID>3</UserID>
<Date>systemDateFormatted</Date>
<Minutes>timeToLog</Minutes>
<Note>userNote</Note>
</Sheet>
So far I have this for my code.
try {
URL url = new URL(theUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("Sheet", null));
params.add(new BasicNameValuePair("Job", jobNumber));
params.add(new BasicNameValuePair("Task", taskNumber));
params.add(new BasicNameValuePair("UserID", String.valueOf(yourUserID)));
params.add(new BasicNameValuePair("Date", systemDateFormatted));
params.add(new BasicNameValuePair("Minutes", timeElapsed));
params.add(new BasicNameValuePair("UserNote", "Test Note"));
params.add(new BasicNameValuePair("Sheet", null));
I'm not sure if I'm understanding NamedValuePair right. Would it be better to create a string for my XML data and POST this way instead?
Thanks!