Apache and android connection problem

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Apache and android connection problem

Postby IdoMajorVA41 » Thu Mar 14, 2013 7:34 pm

Hi whatsup?
i have set on my laptop apache v7 server which is running on port 80
and all i did in the doGet function is:
PrintWriter writer = response.getWriter();
writer.println("Hello Android!!!");
in the android application i made a URL like this :
private final String URL = "http://10.0.2.2:80/Tirgol/main";

the program that runs in the server called Tirgol and there is a servlet named main and all he does is the top code in this comment
When i try to open a connection in the browser with one of these:
http://localhost:80
http://localhost:80/Tirgol/main
http://localhost
localhost

i can see the apache page.
when i try to connect to the apache server from an android emulator it doesnt work
the code i did in android is :

public class MainActivity extends Activity {

TextView header;
Button connect;
private final String URL = "http://10.0.2.2:80/Tirgol/main";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
header = (TextView) findViewById(R.id.header);
connect = (Button) findViewById(R.id.button1);
connect.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String output = " bye";
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(URL);

HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
output = EntityUtils.toString(httpEntity);
} catch (Exception e) {
e.printStackTrace();
}
header.setText(output);
}
});
}
}

Every time i do press the connect button i get "" - which means i get nothing back and i am getting crazy about because i doing every step by the manual :)
And i did use the INTENET premission in the manifest
Please help me and Thanks
IdoMajorVA41
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Mar 14, 2013 7:24 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 1 guest