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

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

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

HttpRequest.setHeader介绍

暂无

代码示例

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

@Override
  public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    @SuppressWarnings("unchecked")
    Map<String, String> uriCustomHeaders = (Map<String, String>) curi.getData().get("customHttpRequestHeaders");
    if (uriCustomHeaders != null) {
      for (Entry<String, String> h: uriCustomHeaders.entrySet()) {
        request.setHeader(h.getKey(), h.getValue());
      }
    }
  }
});

代码示例来源:origin: rest-assured/rest-assured

public void process( final HttpRequest req,
      final HttpContext context ) throws HttpException, IOException {
    
    // set the Accept-Encoding header:
    String encoding = getContentEncoding();            
    if ( !req.containsHeader( ACCEPT_ENC_HDR ) )
      req.addHeader( ACCEPT_ENC_HDR, encoding );
    else {
      StringBuilder values = new StringBuilder();
      for ( Header h : req.getHeaders( ACCEPT_ENC_HDR ) )
        values.append( h.getValue() ).append( "," );
      String encList = (!values.toString().contains( encoding )) ? values
          .append( encoding ).toString()
          : values.toString().substring( 0, values.lastIndexOf( "," ) );
          
      req.setHeader( ACCEPT_ENC_HDR, encList );
    }
    //TODO compress request and add content-encoding header.
  }
}

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

public void process(final HttpRequest request, final HttpContext context) 
    throws HttpException, IOException {
  if (request == null) {
    throw new IllegalArgumentException
      ("HTTP request may not be null.");
  }
  if ((request instanceof HttpEntityEnclosingRequest) &&
    !request.containsHeader(HTTP.DATE_HEADER)) {
    String httpdate = DATE_GENERATOR.getCurrentDate();
    request.setHeader(HTTP.DATE_HEADER, httpdate); 
  }
}

代码示例来源:origin: rest-assured/rest-assured

request.setHeader(entry.getKey(), entry.getValue());

代码示例来源:origin: jamesagnew/hapi-fhir

private void setAuth(HttpRequest httpget) {
 if (password != null) {
  try {
   byte[] b = Base64.encodeBase64((username+":"+password).getBytes("ASCII"));
   String b64 = new String(b, StandardCharsets.US_ASCII);
   httpget.setHeader("Authorization", "Basic " + b64);
  } catch (UnsupportedEncodingException e) {
  }
 }
}

代码示例来源:origin: mitre/HTTP-Proxy-Servlet

private void setXForwardedForHeader(HttpServletRequest servletRequest,
                  HttpRequest proxyRequest) {
 if (doForwardIP) {
  String forHeaderName = "X-Forwarded-For";
  String forHeader = servletRequest.getRemoteAddr();
  String existingForHeader = servletRequest.getHeader(forHeaderName);
  if (existingForHeader != null) {
   forHeader = existingForHeader + ", " + forHeader;
  }
  proxyRequest.setHeader(forHeaderName, forHeader);
  String protoHeaderName = "X-Forwarded-Proto";
  String protoHeader = servletRequest.getScheme();
  proxyRequest.setHeader(protoHeaderName, protoHeader);
 }
}

代码示例来源:origin: com.jayway.restassured/rest-assured

public void process( final HttpRequest req,
      final HttpContext context ) throws HttpException, IOException {
    
    // set the Accept-Encoding header:
    String encoding = getContentEncoding();            
    if ( !req.containsHeader( ACCEPT_ENC_HDR ) )
      req.addHeader( ACCEPT_ENC_HDR, encoding );
    else {
      StringBuilder values = new StringBuilder();
      for ( Header h : req.getHeaders( ACCEPT_ENC_HDR ) )
        values.append( h.getValue() ).append( "," );
      String encList = (!values.toString().contains( encoding )) ? values
          .append( encoding ).toString()
          : values.toString().substring( 0, values.lastIndexOf( "," ) );
          
      req.setHeader( ACCEPT_ENC_HDR, encList );
    }
    //TODO compress request and add content-encoding header.
  }
}

代码示例来源:origin: com.jayway.restassured/rest-assured

public void process(HttpRequest request, HttpContext ctx) throws HttpException, IOException {
  try {
    HttpHost host = (HttpHost) ctx.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    final URI requestURI = new URI(host.toURI()).resolve(request.getRequestLine().getUri());
    Verb verb = Verb.valueOf(request.getRequestLine().getMethod().toUpperCase());
    OAuthRequest oauthRequest = new OAuthRequest(verb, requestURI.toString());
    this.service = getOauthService(isOAuth1);
    service.signRequest(token, oauthRequest);
    if (signature == OAuthSignature.HEADER) {
      //If signature is to be added as header
      for (Map.Entry<String, String> entry : oauthRequest.getHeaders().entrySet()) {
        request.setHeader(entry.getKey(), entry.getValue());
      }
    } else {
      //If signature is to be added as query param
      URI uri = new URI(oauthRequest.getCompleteUrl());
      ((RequestWrapper) request).setURI(uri);
    }
  } catch (URISyntaxException ex) {
    throw new HttpException("Error rebuilding request URI", ex);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@Override
  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    request.setHeader(HttpHeader.ACCEPT, value_);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@Override
  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    request.setHeader(HttpHeader.USER_AGENT, value_);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@Override
  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    request.setHeader(HttpHeader.UPGRADE_INSECURE_REQUESTS, value_);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@Override
  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    request.setHeader(HttpHeader.ACCEPT_LANGUAGE, value_);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@Override
  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    request.setHeader(HttpHeader.HOST, value_);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@Override
  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    request.setHeader("Accept-Encoding", value_);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@Override
  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    request.setHeader(HttpHeader.REFERER, value_);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@Override
  public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    request.setHeader(HttpHeader.DNT, value_);
  }
}

代码示例来源:origin: net.sourceforge.htmlunit/htmlunit

@Override
  public void process(final HttpRequest request, final HttpContext context)
    throws HttpException, IOException {
    for (final Map.Entry<String, String> entry : map_.entrySet()) {
      request.setHeader(entry.getKey(), entry.getValue());
    }
  }
}

代码示例来源:origin: OpenNMS/opennms

@Override
  public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    Header host = request.getFirstHeader(HTTP.TARGET_HOST);
    if (host != null) {
      if (host.getValue().endsWith(":80") || host.getValue().endsWith(":443")) {
        request.setHeader(HTTP.TARGET_HOST, host.getValue().replaceFirst(":\\d+", ""));
        LOG.info("httpRequestInterceptor: removing default port from host header");
      }
    }
  }
});

代码示例来源:origin: SpringForAll/springcloud-thoth

private static void setCookie(HttpRequest request, Cookie[] cookies) {
  if (cookies != null && cookies.length > 0) {
    List<String> cookieStr = new LinkedList<>();
    for (Cookie cookie : cookies) {
      cookieStr.add(cookie.getName() + "=" + cookie.getValue());
    }
    request.setHeader("Cookie", StringUtils.join(cookieStr, "; "));
  }
}

代码示例来源:origin: ibinti/bugvm

@Override
public void process(final HttpRequest request, final HttpContext context)
    throws HttpException, IOException {
  Args.notNull(request, "HTTP request");
  if ((request instanceof HttpEntityEnclosingRequest) &&
    !request.containsHeader(HTTP.DATE_HEADER)) {
    final String httpdate = DATE_GENERATOR.getCurrentDate();
    request.setHeader(HTTP.DATE_HEADER, httpdate);
  }
}

相关文章