Home > Mobile >  Mobile browser can access the link but okhttp connection timeout problems?
Mobile browser can access the link but okhttp connection timeout problems?

Time:03-14

As title,
Computer use wamp server setup, the WWW directory has a index. The PHP file, mobile phones can access this page via a browser to access the computer IP,
But will get prompt in okhttp connection timeout (10000 ms)

Has joined the android: in AndroidManifest usesCleartextTraffic="true" attribute
Mainactivity code:
What is wrong?
 package com. Test. Testokhttp; 

The import androidx. Appcompat. App. AppCompatActivity;

The import android. OS. Bundle;

Import the Java. IO. IOException;

The import okhttp3. OkHttpClient;
The import okhttp3. Request;
The import okhttp3. The Response;

Public class MainActivity extends AppCompatActivity {
Private final String url="http://192.168.28.162/";//mobile browser access to

@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Activity_main);
New Thread (this: get.) start ();
}

Public void the get () {
OkHttpClient client=new OkHttpClient ();
Request the Request=new Request. Builder ()
Url (url)
.build();
Try {
The Response the Response=client. NewCall (request). The execute ();
System. Out. Println (the response body (). The string ());
} the catch (IOException e) {
e.printStackTrace();
}
}
}
  • Related