message : java.io.FileNotFoundException: http://XXX.XXX.XXX.XXX/XXXXX
或者回應401的情況
之後大概查詢有關401的基本意思 : 必須要使用者資訊
如下 :
我們要做的動作就是執行連結時,也必須要把使用者資訊也一起帶進去
BufferedReader rd = null;
try {
URL url = new URL(urlString);
HttpURLConnection httpconn = (HttpURLConnection) url
.openConnection();
String authCombination = "admin" + ":" + "admin";
String accountCode = Base64.encodeToString(authCombination.getBytes(),
Base64.DEFAULT);
httpconn.setRequestProperty("Authorization", "Basic "+ accountCode);
httpconn.setConnectTimeout(4000);
httpconn.setReadTimeout(4000);
httpconn.connect();
rd = new BufferedReader(new InputStreamReader(
httpconn.getInputStream()));
int returnCode = httpconn.getResponseCode();
if (returnCode == 200) {
} else {
}
} catch (MalformedURLException e) {
} catch (IOException e) {
} finally {
try {
if (rd != null)
rd.close();
} catch (IOException e) {
}
}
歡迎轉載,請註明出處 。
沒有留言:
張貼留言