本文整理匯總了Java中java.net.HttpURLConnection.getContent方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpURLConnection.getContent方法的具體用法?Java HttpURLConnection.getContent怎麽用?Java HttpURLConnection.getContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.net.HttpURLConnection
的用法示例。
在下文中一共展示了HttpURLConnection.getContent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendOCSPReq
import java.net.HttpURLConnection; //導入方法依賴的package包/類
private OCSPResp sendOCSPReq(OCSPReq request, String url) throws IOException {
byte[] bytes = request.getEncoded();
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestProperty("Content-Type", "application/ocsp-request");
connection.setRequestProperty("Accept", "application/ocsp-response");
connection.setDoOutput(true);
this.log.debug("Sending OCSP request to <{}>", url);
DataOutputStream outputStream = new DataOutputStream(new BufferedOutputStream(connection.getOutputStream()));
outputStream.write(bytes);
outputStream.flush();
outputStream.close();
if (connection.getResponseCode() != 200) {
this.log.error("OCSP request has been failed (HTTP {}) - {}", connection.getResponseCode(),
connection.getResponseMessage());
}
try (InputStream in = (InputStream) connection.getContent()) {
return new OCSPResp(in);
}
}
示例2: run
import java.net.HttpURLConnection; //導入方法依賴的package包/類
@Override
public void run() {
try {
HttpURLConnection request = (HttpURLConnection) new URL("https://api.github.com/repos/TheAndroidMaster/MediaNotification/contributors").openConnection();
request.connect();
JsonReader reader = new JsonReader(new InputStreamReader((InputStream) request.getContent()));
reader.setLenient(true);
reader.beginArray();
reader.skipValue();
while (reader.hasNext()) {
reader.beginObject();
String name = null, imageUrl = null, url = null;
while (reader.hasNext()) {
switch (reader.nextName()) {
case "login":
name = reader.nextString();
break;
case "avatar_url":
imageUrl = reader.nextString();
break;
case "html_url":
url = reader.nextString();
break;
default:
reader.skipValue();
}
}
contributors.add(new ContributorData(name, imageUrl, url));
reader.endObject();
}
reader.endArray();
} catch (Exception ignored) {
}
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
AboutDialog dialog = dialogReference.get();
if (dialog != null) {
dialog.contributorView.getAdapter().notifyDataSetChanged();
for (final ContributorData contributor : contributors) {
new ContributorThread(dialog, contributor).start();
}
}
}
});
}