当前位置: 首页>>代码示例>>Java>>正文


Java HttpURLConnection.getContent方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:e-gov,项目名称:TARA-Server,代码行数:20,代码来源:OCSPValidator.java

示例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();
                }
            }
        }
    });
}
 
开发者ID:TheAndroidMaster,项目名称:MediaNotification,代码行数:49,代码来源:AboutDialog.java


注:本文中的java.net.HttpURLConnection.getContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。