Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top