Android: sending xml as document object, POST method
Posted
by
juro
on Stack Overflow
See other posts from Stack Overflow
or by juro
Published on 2010-12-28T08:02:22Z
Indexed on
2010/12/28
9:53 UTC
Read the original article
Hit count: 219
i am new at programming and i need some help with that please =/
web service is already written but not by me. so all i have to do is send xml as document object by post method through web service.
my code:
public class send extends application {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://app.local/test/");
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element rootElement = document.createElement("packet");
rootElement.setAttribute("version", "1.2");
document.appendChild(rootElement);
Element em = document.createElement("imei");
em.appendChild(document.createTextNode("000000000000000"));
rootElement.appendChild(em);
em = document.createElement("username");
em.appendChild(document.createTextNode("5555"));
rootElement.appendChild(em);
HttpResponse response = httpclient.execute(httppost);
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
}
}
© Stack Overflow or respective owner