Script File in Android
While building android application we have situations where we want to post data onto the server. Sometimes we need response from the server and based on that response action will be performed.
For doing that we will create script files on our server which gets called from our android application while submitting data. Script file will contain the code to save data into the server database as well returning the response in form of JSON.
We can use HTTPGet and HTTPPost for sending requests and getting response from server
HttpGet httpget = new HttpGet("http://myserverdomain/script.php?var1=savedata");
HttpResponse response = httpclient.execute(httpget);
if(response != null) {
String line = "";
InputStream inputstream = response.getEntity().getContent();
line = convertStreamToString(inputstream);
Toast.makeText(this, line, Toast.LENGTH).show();
}
else
{
Toast.makeText(this, "Unable to complete your request", Toast.LENGTH).show();
}
I am using PHP file named myscript.php for writing script and it is hosted on myserverdomain and i am also sending querystring for setting flags
Toast method is used to display message in android programming
0 Comment(s)