當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpURLConnection.getRequestProperty方法代碼示例

本文整理匯總了Java中java.net.HttpURLConnection.getRequestProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpURLConnection.getRequestProperty方法的具體用法?Java HttpURLConnection.getRequestProperty怎麽用?Java HttpURLConnection.getRequestProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.HttpURLConnection的用法示例。


在下文中一共展示了HttpURLConnection.getRequestProperty方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addRequestHeaders

import java.net.HttpURLConnection; //導入方法依賴的package包/類
/**
 * Add custom headers for this download to the HTTP request.
 */
private void addRequestHeaders(HttpURLConnection conn, boolean resuming) {
    for (Pair<String, String> header : mInfo.getHeaders()) {
        conn.addRequestProperty(header.first, header.second);
    }

    // Only splice in user agent when not already defined
    if (conn.getRequestProperty("User-Agent") == null) {
        conn.addRequestProperty("User-Agent", mInfo.getUserAgent());
    }

    // Defeat transparent gzip compression, since it doesn't allow us to
    // easily resume partial downloads.
    conn.setRequestProperty("Accept-Encoding", "identity");

    // Defeat connection reuse, since otherwise servers may continue
    // streaming large downloads after cancelled.
    conn.setRequestProperty("Connection", "close");

    if (resuming) {
        if (mInfoDelta.mETag != null) {
            conn.addRequestProperty("If-Match", mInfoDelta.mETag);
        }
        conn.addRequestProperty("Range", "bytes=" + mInfoDelta.mCurrentBytes + "-");
    }
}
 
開發者ID:redleaf2002,項目名稱:downloadmanager,代碼行數:29,代碼來源:DownloadThread.java

示例2: getRequestContentLength

import java.net.HttpURLConnection; //導入方法依賴的package包/類
/**
 * Get the content length of the request in the given HTTP connection.
 * @param connection The connection.
 * @return The content length, or zero if not found.
 */
private long getRequestContentLength(HttpURLConnection connection) {
  String lengthString = connection.getRequestProperty(
      HeaderConstants.CONTENT_LENGTH);
  if (lengthString != null){
    return Long.parseLong(lengthString);
  }
  else{
    return 0;
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:16,代碼來源:ResponseReceivedMetricUpdater.java

示例3: call

import java.net.HttpURLConnection; //導入方法依賴的package包/類
private <T> T call(HttpURLConnection conn, Map jsonOutput,
    int expectedResponse, Class<T> klass, int authRetryCount)
    throws IOException {
  T ret = null;
  try {
    if (jsonOutput != null) {
      writeJson(jsonOutput, conn.getOutputStream());
    }
  } catch (IOException ex) {
    IOUtils.closeStream(conn.getInputStream());
    throw ex;
  }
  if ((conn.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN
      && (conn.getResponseMessage().equals(ANONYMOUS_REQUESTS_DISALLOWED) ||
          conn.getResponseMessage().contains(INVALID_SIGNATURE)))
      || conn.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
    // Ideally, this should happen only when there is an Authentication
    // failure. Unfortunately, the AuthenticationFilter returns 403 when it
    // cannot authenticate (Since a 401 requires Server to send
    // WWW-Authenticate header as well)..
    KMSClientProvider.this.authToken =
        new DelegationTokenAuthenticatedURL.Token();
    if (authRetryCount > 0) {
      String contentType = conn.getRequestProperty(CONTENT_TYPE);
      String requestMethod = conn.getRequestMethod();
      URL url = conn.getURL();
      conn = createConnection(url, requestMethod);
      conn.setRequestProperty(CONTENT_TYPE, contentType);
      return call(conn, jsonOutput, expectedResponse, klass,
          authRetryCount - 1);
    }
  }
  try {
    AuthenticatedURL.extractToken(conn, authToken);
  } catch (AuthenticationException e) {
    // Ignore the AuthExceptions.. since we are just using the method to
    // extract and set the authToken.. (Workaround till we actually fix
    // AuthenticatedURL properly to set authToken post initialization)
  }
  HttpExceptionUtils.validateResponse(conn, expectedResponse);
  if (conn.getContentType() != null
      && conn.getContentType().trim().toLowerCase()
          .startsWith(APPLICATION_JSON_MIME)
      && klass != null) {
    ObjectMapper mapper = new ObjectMapper();
    InputStream is = null;
    try {
      is = conn.getInputStream();
      ret = mapper.readValue(is, klass);
    } finally {
      IOUtils.closeStream(is);
    }
  }
  return ret;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:56,代碼來源:KMSClientProvider.java


注:本文中的java.net.HttpURLConnection.getRequestProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。