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:

Source: Internet
Author: User

============ 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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.