Answer the question
In order to leave comments, you need to log in
How to read data from php script in android application?
Hello. I have an android app. I asked a question about it, they advised me to write a script that the application will access and update the change data. The script was written and posted on the hosting:
<?php
$gos = "2500";
$baz = "4050";
echo $gos.'<br />';
echo $baz;
?>
public static void connect(String url)
{
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response;
try {
response = httpclient.execute(httpget);
Log.i("Praeda", response.getStatusLine().toString());
HttpEntity entity = response.getEntity();
if (entity != null)
{
InputStream instream = entity.getContent();
String result = convertStreamToString(instream);
instream.close();
}
} catch (Exception e) {}
}
private static String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
Answer the question
In order to leave comments, you need to log in
I did based on an example like this
stackoverflow.com/questions/13458878/sending-post-...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question