============ Problem Description ============
private static final String URL = "";
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
TV = (TextView) This.findviewbyid (R.ID.TEXTVIEW2);
user = (EditText) This.findviewbyid (R.ID.EDITTEXT1);
Password = (EditText) This.findviewbyid (R.ID.EDITTEXT2);
Button = (button) This.findviewbyid (R.id.button1);
Button.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
TODO auto-generated Method Stub
Enabling the ability to connect to a server
Init ();
}
Use the Post method to achieve
private void init () {
TODO auto-generated Method Stub
Boolean flag = false; Mark of success or not
String user1 = User.gettext (). toString (). Trim ();
String Password1 = Password.gettext (). toString (). Trim ();
try {
HttpPost request = new HttpPost (URL);
list<namevaluepair> parms = new arraylist<namevaluepair> ();
Parms.add (New Basicnamevaluepair ("id", user));
Parms.add (New Basicnamevaluepair ("password", Password1));
Request.setentity (New Urlencodedformentity (Parms,
HTTP. Utf_8));
HttpResponse response = new Defaulthttpclient ()
. Execute (Request);
if (Response.getstatusline (). Getstatuscode ()! = 404) {//Now we've found the data.
Flag = Boolean.parseboolean (entityutils.tostring (Response.getentity ()). Trim ());
Response.getstatusline (). Getstatuscode ());
}
} catch (Exception e) {
Todo:handle exception
Tv.settext ("Web server Connection Failed ...");
}
if (flag) {
Tv.settext ("User Login successful! "+ flag);
} else {
Tv.settext ("User Login failed! "+ flag);
}
}
});
}
============ Solution 1============
Where's your URL? Not given a specific IP path? The emulator is already on the computer and has direct access to the server.
You need to turn off the computer firewall on the real machine and access it through the specific intranet IP address. The real machine and the server should be in the same LAN
Android client interacts with the server, the emulator can get the response of the server, but the real machine does not get the response of the server, excuse me? The program is as follows: