【已解决】 Android开发之网络编程抛异常(代码除URL外一致)
// 代码如下
try {
URL url = new URL("https://shop.sunofbeach.net/");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(10000);
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9");
urlConnection.setRequestProperty("Accept", "*/*");
Log.i(TAG, "urlConnection" + urlConnection);
Log.i(TAG, "准备connect()");
urlConnection.connect();
int responseCode = urlConnection.getResponseCode();
Log.i(TAG, "responseCode -->" + responseCode);
} catch (Exception e) {
Log.e(TAG, "getCause -->" + e.getCause());
Log.e(TAG, "getClass -->" + e.getClass());
Log.e(TAG, "getMessage -->" + e.getMessage());
Log.e(TAG, "准备connect()失败");
}


基础不行呀,得补习基础呀。
你把整个exception打出来不好么?
网络请求不可以在主线程进行。