0
我正在學習android中的網絡,以便我可以從網站API獲取內容。我正在閱讀Udacity教程,並瞭解了製作HttpURLConnection所需的這些代碼行。但是如果我必須從Https網址中提取內容呢?請在下面的代碼中建議對HttpsURL連接進行哪些修改。Android中的HttpsURLConnection
HttpURLConnection類:
private String makeHttpRequest(URL url) throws IOException {
String jsonResponse = "";
HttpURLConnection urlConnection = null;
InputStream inputStream = null;
try {
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setReadTimeout(10000 /* milliseconds */);
urlConnection.setConnectTimeout(15000 /* milliseconds */);
urlConnection.connect();
inputStream = urlConnection.getInputStream();
jsonResponse = readFromStream(inputStream);
} catch (IOException e) {
// TODO: Handle the exception
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
if (inputStream != null) {
// function must handle java.io.IOException here
inputStream.close();
}
}
return jsonResponse;
這個鏈接可以幫助你http://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically – rogerwar