當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。