0
私はアンドロイドのネットワークを学んでいるので、ウェブサイトAPIからコンテンツを取得できます。私はUdacityのチュートリアルを見て、HttpURLConnectionを作るために必要なこれらのコード行を知る必要がありました。しかし、もし私がHttpsのURLからコンテンツを引き出す必要があればどうしますか? HttpsURL接続の場合、以下のコードでどのような変更が必要かをご提案ください。HttpsURLConnection in Android
の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