Home > Back-end >  Android okhttp client access server problem! Be urgent!!!!
Android okhttp client access server problem! Be urgent!!!!

Time:09-29

Public void login (View View)
{
The String url="http://10.0.2.2/myserver_war_exploded/userLogin.html";
String username=((EditText) the findViewById (R.i d.u sername)). The getText (), toString ();//get the user name
String password=((EditText) the findViewById (R.i d.p assword)). The getText (), toString ();//get the password
OkHttpClient client=new OkHttpClient ();
//create RequestBody object, add parameters
RequestBody RequestBody=new FormBody. Builder (). The add (" username ", username). The add (" password, "password). The build ();
//create a post method request object
Request the Request=new Request. The Builder (). The post (requestBody). Url (url). The build ();
Client. NewCall (request). The enqueue (new Callback ()
{
@ Override
Public void onFailure (Call Call, IOException e)
{
If (e instanceof ConnectException) {
The e (" frost_connection ", um participant etMessage ());
System. The out. Println (" fail1 ");
}
System. The out. Println (" fail2 ");
}

@ Override
Public void onResponse (Call the Call, the Response Response) throws IOException
{
If (response. IsSuccessful ())
{
System. The out. Println (" connection success ");
}
}
});
}
Anyway is onfailure, directly to the browser in the avd virtual machine could not get access 10.0.2.2, please understand the android client and server side great god answers,
Backend server is also the native implementation, try to request can use the server accept yesterday, not today, there is no problem on the server, use the computer browser can access, post yesterday trying to successful solutions:
Manifests added:


Application tag added:
Android: usesCleartextTraffic="true"

CodePudding user response:

Resolved url address errors
  • Related