I have a hosted website in php. The android app tries to open a web page happy.php. When I try to run this app, instead of displaying yayyyy in the textview, failed is shown. Please help me to find the error
public class MainActivity extends ActionBarActivity {
Button b;
TextView t;
String n;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.button);
t=(TextView)findViewById(R.id.textView);
b.setOnClickListener( new View.OnClickListener(){
public void onClick(View v)
{try {
DefaultHttpClient d = new DefaultHttpClient();
HttpPost p = new HttpPost("http://www.palakarora.net16.net/happy.php");
HttpResponse httpResponse = d.execute(p);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream is = httpEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
n = reader.readLine();
}
catch(Exception e)
{
n="failed";
}
t.setText(n);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
happy.php is the web page called by android app. the page prints "yayyyy". happy.php
<?
print("yayyyyy");
?>