I aldready succed retrieving http values from the web.
However, I still rarely have an idea how I retrieved value from the web.
I have a code. But, without understanding it, what is it for?
So… I want to ask three things to understand my code.
HTTPGet, HTTPClient, EntityUtils.
I am just guessing what HTTPGet does is grabbing http data which made by http coding.
and I am guessing HTTPClient is for data encapsulation.
and.. EntityUtils? I really dont have a idea. what is entitiy? why do I need this
to get HTTPresponse as a string? what does he do?
below is my code.
HttpGet get = new HttpGet(tempURL);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(get);
String responseBody = EntityUtils.toString(response.getEntity());
When you send a HTTP request by using GET or POST method, it will send you a response. If there is nothing to send, at least the server sends the status code. As an example 200 status code stands for “OK”.
So, by using EntityUtils, or
will give you the response in a human readable format. If you have send a request to a PHP page you will echo values as response. These are two examples for GET and POST to understand with full Android source code and PHP source code.