I ran into some problem and need some help (please)!
I am very new to Android Dev (and for coding in general). Basically, I need POST XML data to be associated with the URL using HttpURLConnection, but cannot make it work. I have an application that reads and processes XML data from a GET request, but it is difficult to find the POST part.
I looked at creating a NameValuePair array, but am not sure how to do this with the XML structure I need to send.
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 am not sure if I understand NamedValuePair correctly. Would it be better to create a string for my XML data and POST instead?
Thanks!
source share