本文整理汇总了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();
}
}
}
});
}