Christopher
Christopher

Reputation: 453

Retriving website after POST in android

I am using java.net.HttpURLConnection to connect to a website and send some data through a POST command. Now I am trying to find out if there is a way to read/parse the resulting website?

The PHP script I am posting to echo's some infromation on the site after the POST and that is what I want to read.

The only feedback I am able to find is the responseCode and responseMessage through getResponseCode() and getResponseMessage() but that is not really what I am looking for.

Is there any good way of doing this?

Upvotes: 0

Views: 285

Answers (2)

dave.c
dave.c

Reputation: 10908

I'm assuming you are doing something like this:

HttpURLConnection urlc = null;
DataOutputStream dataout = null;
URL url = new URL(URL_LOGIN_SUBMIT);
urlc = (HttpURLConnection) url.openConnection();
// set up post
...
dataout = new DataOutputStream(urlc.getOutputStream());
dataout.writeBytes(output);
int responseCode = urlc.getResponseCode();

If so, you can add this part:

BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream()),8096);
String response;
while ((response = in.readLine()) != null) {
    System.out.println(response);
}
...

It will just write the output to the System.out but it should give you a start.

Upvotes: 1

Mark B
Mark B

Reputation: 200860

See the answer to this question: Reading HttpPost response

Upvotes: 0

Related Questions