Question

I am sending data to server using HttpPost in android which is successfully received by server. Now the server response is as follows:

<html><body>
<input type="text" id="nameL" name="nameL" value="Sam" />
<input type="text" id="level" name="level" value="Introductory"  />
</body></html>

How can I get value of http response using the input name attribute (e.g. nameL & level) on an Android client? I am able to get the string response but it contains all tags <html>....</html> (as above) in one string.

Was it helpful?

Solution

Use an HTML parser. I personally like jsoup:

Document doc = JSoup.parse(responseString);
String nameL = doc.select("input[name=nameL]").attr("value");
String level = doc.select("input[name=level]").attr("value");

However, as VenomVendor pointed out, it is unusual (and inefficient, by the way) to use HTML for API-like communication.

OTHER TIPS

Either generate JSON or XML response from server side.
Use XML Parsing or JSON PARSING to retrieve data.

your current response will be useful, only when you are adding the response to WebView

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top