Note: This is just an example. The scalability and reusability are poor. I just put forward an idea and the returned XML parsing code is also poorly written.
You can solve these problems when using code.
========================================================== ===
Key code:
Try {
// Post machine principle, simulating Browser
Final string server_url = "http: // 10.40.15.11/Android/WebService. asmx"; // define the source address of the content to be obtained
URL url = new URL (server_url );
Urlconnection con = URL. openconnection ();
Con. setdooutput (true );
Con. setrequestproperty ("Pragma:", "No-Cache ");
Con. setrequestproperty ("cache-control", "No-Cache ");
Con. setrequestproperty ("Content-Type", "text/XML ");
Outputstreamwriter out = new outputstreamwriter (con
. Getoutputstream ());
// Control Value
Edittext etextname = (edittext) findviewbyid (R. Id. tbx_name );
Edittext etextage = (edittext) findviewbyid (R. Id. tbx_age );
String xmlinfo = "<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"?> <Soap12: envelope xmlns: xsi = \ "comment" xmlns: XSD = \ "http://www.w3.org/2001/xmlschema\" xmlns: soap12 = \ "comment"> <soap12: body> <showentity xmlns = \ "http://tempuri.org/\"> <person> <Name>"
+ Urlencoder. encode (etextname. gettext (). tostring ())
+ "</Name> <age>"
+ Etextage. gettext (). tostring ()
+ "</Age> </person> </showentity> </soap12: Body> </soap12: envelope> ";
// Send
Out. Write (new string (xmlinfo. getbytes ("UTF-8 ")));
Out. Flush ();
Out. Close ();
// Return Value
Bufferedreader BR = new bufferedreader (New inputstreamreader (con
. Getinputstream ()));
Stringbuilder sbuilder = new stringbuilder ();
String line = "";
For (line = Br. Readline (); line! = NULL; line = Br. Readline ()){
Sbuilder. append (line );
}
// Parse XML
Pattern patternname = pattern. Compile ("<Name> .*? </Name> ");
Matcher matchername = patternname. matcher (sbuilder. tostring ());
If (matchername. Find ()){
String name = matchername. Group ();
Textview lblname = (textview) findviewbyid (R. Id. lbl_name );
Lblname. settext (urldecoder. Decode (name. substring (name
. Indexof (">") + 1, name. lastindexof ("<"))));
}
Pattern patternage = pattern. Compile ("<age> .*? </Age> ");
Matcher matcherage = patternage. matcher (sbuilder. tostring ());
If (matcherage. Find ()){
String age = matcherage. Group ();
Textview lblage = (textview) findviewbyid (R. Id. lbl_age );
Lblage. settext (age. substring (age. indexof (">") + 1, age
. Lastindexof ("<")));
}
} Catch (exception e ){
String STR = E. getmessage ();
}
The xmlinfo variable is the place where the red lines are circled.
Server: C # code
[Webmethod]
Public Person showentity (person)
{
Return person;
}
Publicclass person
{
Publicstring name {Get; set ;}
Publicint age {Get; set ;}
}