Android - Using HttpURLConnection to POST XML data -


i've run bit of deadend , need bit of (please)!

i'm new android dev (and coding in general). need post xml data url using httpurlconnection can't work. i've got app reading , pasrsing xml data request finding post part difficult.

i've looked @ creating namevaluepair array not sure how xml structure needing post.

the xml data this:

<sheet>   <job>jobnumber</job>    <task>tasknumber</task>    <userid>3</userid>    <date>systemdateformatted</date>    <minutes>timetolog</minutes>    <note>usernote</note> </sheet> 

so far have 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. better create string xml data , post way instead?

thanks!

yes, post data goes payload of request. example

url url = new url(theurl); httpurlconnection conn = (httpurlconnection) url.openconnection(); try {     conn.setreadtimeout(10000);     conn.setconnecttimeout(15000);     conn.setrequestmethod("post");     conn.setdoinput(true);     conn.setdooutput(true);     string body = "<xml...</xml>";     outputstream output = new bufferedoutputstream(conn.getoutputstream());     output.write(body.getbytes());     output.flush(); {     conn.disconnect(); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -