当前位置: 首页>>代码示例>>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;未经允许,请勿转载。