1
我試着做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();
如果我跑,並安裝應用程序,它成功了。
或我替換爲http://www.google.com
與https://www.google.com
,它也在即時應用程序中成功運行。
即時應用只支持Https嗎?