本文介绍了不支持即时应用程序CLEARTEXT通信:[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试做HttpUrlConnection
,但出现例外:
java.net.UnknownServiceException: CLEARTEXT communication not supported: []
at com.android.okhttp.Connection.connect(Connection.java:149)
at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:185)
at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:341)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:433)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:114)
at com.xfzj.instantappdemo2.feature.MainActivity$3.run(MainActivity.java:84)
at java.lang.Thread.run(Thread.java:818)
这是我的代码:
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL("http://www.google.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
Log.i("responseCode",""+connection.getResponseCode());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
如果我运行并安装了该应用程序,则成功.
If I ran and installed the app, it succeeded.
或者我将http://www.google.com
替换为https://www.google.com
,它在即时应用程序中也成功运行.
or I replaced http://www.google.com
with https://www.google.com
, it also ran successfully in instant app.
即时应用程序仅支持Https吗?
Does instant app only support Https?
推荐答案
是的.不支持HTTP连接: https://developer.android.com/topic /instant-apps/policy.html#network_traffic .
That's right. HTTP connections are unsupported: https://developer.android.com/topic/instant-apps/policy.html#network_traffic.
这篇关于不支持即时应用程序CLEARTEXT通信:[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!