org.apache.http.Header.getName()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中org.apache.http.Header.getName()方法的一些代码示例,展示了Header.getName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Header.getName()方法的具体详情如下:
包路径:org.apache.http.Header
类名称:Header
方法名:getName

Header.getName介绍

[英]Get the name of the Header.
[中]获取标题的名称。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public HttpHeaders getHeaders() {
  if (this.headers == null) {
    this.headers = new HttpHeaders();
    for (Header header : this.httpResponse.getAllHeaders()) {
      this.headers.add(header.getName(), header.getValue());
    }
  }
  return this.headers;
}

代码示例来源:origin: code4craft/webmagic

public static Map<String,List<String>> convertHeaders(Header[] headers){
    Map<String,List<String>> results = new HashMap<String, List<String>>();
    for (Header header : headers) {
      List<String> list = results.get(header.getName());
      if (list == null) {
        list = new ArrayList<String>();
        results.put(header.getName(), list);
      }
      list.add(header.getValue());
    }
    return results;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public HttpHeaders getHeaders() {
  if (this.headers == null) {
    this.headers = new HttpHeaders();
    for (Header header : this.httpResponse.getAllHeaders()) {
      this.headers.add(header.getName(), header.getValue());
    }
  }
  return this.headers;
}

代码示例来源:origin: stackoverflow.com

message.getAllHeaderLines();
for (Enumeration<Header> e = message.getAllHeaders(); e.hasMoreElements();) {
  Header h = e.nextElement();
  h.getName();
  h.getValue();
}

代码示例来源:origin: org.springframework/spring-web

@Override
public HttpHeaders getHeaders() {
  if (this.headers == null) {
    this.headers = new HttpHeaders();
    for (Header header : this.httpResponse.getAllHeaders()) {
      this.headers.add(header.getName(), header.getValue());
    }
  }
  return this.headers;
}

代码示例来源:origin: apache/hbase

public String getHeader(String key) {
 for (Header header: headers) {
  if (header.getName().equalsIgnoreCase(key)) {
   return header.getValue();
  }
 }
 return null;
}

代码示例来源:origin: org.springframework/spring-web

@Override
public HttpHeaders getHeaders() {
  if (this.headers == null) {
    this.headers = new HttpHeaders();
    for (Header header : this.httpResponse.getAllHeaders()) {
      this.headers.add(header.getName(), header.getValue());
    }
  }
  return this.headers;
}

代码示例来源:origin: androidquery/androidquery

public String getHeader(String name){
  
  if(headers == null) return null;	
  
  for(int i = 0; i < headers.length; i++){
    if(name.equalsIgnoreCase(headers[i].getName())){
      return headers[i].getValue();
    }
  }
  
  return null;
}

代码示例来源:origin: wiztools/rest-client

static String getHTTPResponseTrace(HttpResponse response) {
  StringBuilder sb = new StringBuilder();
  sb.append(response.getStatusLine()).append('\n');
  for (Header h : response.getAllHeaders()) {
    sb.append(h.getName()).append(": ").append(h.getValue()).append('\n');
  }
  sb.append('\n');
  HttpEntity e = response.getEntity();
  if (e != null) {
    appendHttpEntity(sb, e);
  }
  return sb.toString();
}

代码示例来源:origin: yasserg/crawler4j

/**
 * Set the default header collection (creating copies of the provided headers).
 */
public void setDefaultHeaders(Collection<? extends Header> defaultHeaders) {
  Collection<BasicHeader> copiedHeaders = new HashSet<>();
  for (Header header : defaultHeaders) {
    copiedHeaders.add(new BasicHeader(header.getName(), header.getValue()));
  }
  this.defaultHeaders = copiedHeaders;
}

代码示例来源:origin: selenide/selenide

protected String getFileName(String fileToDownloadLocation, HttpResponse response) {
 for (Header header : response.getAllHeaders()) {
  Optional<String> fileName = httpHelper.getFileNameFromContentDisposition(header.getName(), header.getValue());
  if (fileName.isPresent()) {
   return fileName.get();
  }
 }
 log.info("Cannot extract file name from http headers. Found headers: ");
 for (Header header : response.getAllHeaders()) {
  log.info(header.getName() + '=' + header.getValue());
 }
 String fullFileName = FilenameUtils.getName(fileToDownloadLocation);
 return isBlank(fullFileName) ? downloader.randomFileName() : trimQuery(fullFileName);
}

代码示例来源:origin: chentao0707/SimplifyReader

/**
   * Converts Headers[] to Map<String, String>.
   */
  protected static Map<String, String> convertHeaders(Header[] headers) {
    Map<String, String> result = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    for (int i = 0; i < headers.length; i++) {
      result.put(headers[i].getName(), headers[i].getValue());
    }
    return result;
  }
}

代码示例来源:origin: rapidoid/rapidoid

private static HttpResp response(HttpResponse response) throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter printer = new PrintWriter(baos);
  printer.print(response.getStatusLine() + "");
  printer.print("\n");
  Map<String, String> headers = U.map();
  for (Header hdr : response.getAllHeaders()) {
    printer.print(hdr.getName());
    printer.print(": ");
    printer.print(hdr.getValue());
    printer.print("\n");
    headers.put(hdr.getName(), hdr.getValue());
  }
  printer.print("\n");
  printer.flush();
  HttpEntity entity = response.getEntity();
  byte[] body = entity != null ? IO.loadBytes(response.getEntity().getContent()) : new byte[0];
  baos.write(body);
  byte[] raw = baos.toByteArray();
  return new HttpResp(raw, response.getStatusLine().getStatusCode(), headers, body);
}

代码示例来源:origin: mcxiaoke/android-volley

/**
   * Converts Headers[] to Map<String, String>.
   */
  protected static Map<String, String> convertHeaders(Header[] headers) {
    Map<String, String> result = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    for (int i = 0; i < headers.length; i++) {
      result.put(headers[i].getName(), headers[i].getValue());
    }
    return result;
  }
}

代码示例来源:origin: jooby-project/jooby

public Response headers(final BiConsumer<String, String> headers)
  throws Exception {
 for (Header header : rsp.getAllHeaders()) {
  headers.accept(header.getName(), header.getValue());
 }
 return this;
}

代码示例来源:origin: jiangqqlmj/FastDev4Android

/**
   * Converts Headers[] to Map<String, String>.
   */
  protected static Map<String, String> convertHeaders(Header[] headers) {
    Map<String, String> result = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
    for (int i = 0; i < headers.length; i++) {
      result.put(headers[i].getName(), headers[i].getValue());
    }
    return result;
  }
}

代码示例来源:origin: internetarchive/heritrix3

/**
 * This method populates <code>curi</code> with response status and
 * content type.
 * 
 * @param curi
 *            CrawlURI to populate.
 * @param response
 *            Method to get response status and headers from.
 */
protected void addResponseContent(HttpResponse response, CrawlURI curi) {
  curi.setFetchStatus(response.getStatusLine().getStatusCode());
  Header ct = response.getLastHeader("content-type");
  curi.setContentType(ct == null ? null : ct.getValue());
  
  for (Header h: response.getAllHeaders()) {
    curi.putHttpResponseHeader(h.getName(), h.getValue());
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public void beforeRequest( Map<String, List<String>> headers ) {
 if ( withAuth ) {
  Header authenticationHeader = getAuthenticationHeader( url );
  if ( authenticationHeader != null ) {
   headers
    .put( authenticationHeader.getName(), Collections.singletonList( authenticationHeader.getValue() ) );
  }
 }
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Creates and initializes an HttpResponse object suitable to be passed to an HTTP response
 * handler object.
 *
 * @param request Marshalled request object.
 * @param method  The HTTP method that was invoked to get the response.
 * @param context The HTTP context associated with the request and response.
 * @return The new, initialized HttpResponse object ready to be passed to an HTTP response
 * handler object.
 * @throws IOException If there were any problems getting any response information from the
 *                     HttpClient method object.
 */
public static HttpResponse createResponse(Request<?> request,
                  HttpRequestBase method,
                  org.apache.http.HttpResponse apacheHttpResponse,
                  HttpContext context) throws IOException {
  HttpResponse httpResponse = new HttpResponse(request, method, context);
  if (apacheHttpResponse.getEntity() != null) {
    httpResponse.setContent(apacheHttpResponse.getEntity().getContent());
  }
  httpResponse.setStatusCode(apacheHttpResponse.getStatusLine().getStatusCode());
  httpResponse.setStatusText(apacheHttpResponse.getStatusLine().getReasonPhrase());
  for (Header header : apacheHttpResponse.getAllHeaders()) {
    httpResponse.addHeader(header.getName(), header.getValue());
  }
  return httpResponse;
}

代码示例来源:origin: square/okhttp

String name = header.getName();
if ("Content-Type".equalsIgnoreCase(name)) {
 contentType = header.getValue();
} else {
 builder.header(name, header.getValue());
  builder.header(encoding.getName(), encoding.getValue());

相关文章