在我的应用程序代码中
@Override
protected String doInBackground(Void... params) {
StringBuilder response = null;
try {
String request = ApplicationConstants.REQUEST_ABOUT_BASE_URI;
URL url = new URL(request);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setReadTimeout(10000); // millis
conn.setConnectTimeout(15000); // millis
conn.connect();
Log.d(TAG, "doInBackground: " + conn.getResponseCode() + " : " + conn.getResponseMessage());
InputStream is = conn.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
response = new StringBuilder();
while((line = rd.readLine()) != null) {
response.append(line);
}
rd.close();
Log.d(TAG, "doInBackground: " + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
return response.toString();
}
崩溃错误
无法解析主机“tools.mysite.com” 但在我的应用程序常量REQUEST_ABOUT_BASE_URI中写tools.mysyte.com/mobile.php?about
只有真正的设备,只有Android 4. +。在Android 5.0 .connect()上没问题。
为什么?