本文整理了Java中org.apache.http.HttpRequest.addHeader()
方法的一些代码示例,展示了HttpRequest.addHeader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.addHeader()
方法的具体详情如下:
包路径:org.apache.http.HttpRequest
类名称:HttpRequest
方法名:addHeader
暂无
代码示例来源:origin: apache/hive
@Override
protected void addHttpAuthHeader(HttpRequest httpRequest, HttpContext httpContext)
throws Exception {
httpRequest.addHeader(HIVE_DELEGATION_TOKEN_HEADER, tokenStr);
}
}
代码示例来源:origin: apache/hive
@Override
public void process(HttpRequest httpRequest, HttpContext httpContext)
throws HttpException, IOException {
if (injectHeader){
httpRequest.addHeader("X-XSRF-HEADER", "true");
}
}
}
代码示例来源:origin: androidquery/androidquery
@Override
public void applyToken(AbstractAjaxCallback<?, ?> cb, HttpRequest request) {
//AQUtility.debug("apply token", token);
request.addHeader("Authorization", "GoogleLogin auth=" + token);
}
代码示例来源:origin: stackoverflow.com
String username = ...
String password = ...
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
HttpRequest request = ...
request.addHeader(new BasicScheme().authenticate(creds, request));
代码示例来源:origin: code4craft/webmagic
public void process(
final HttpRequest request,
final HttpContext context) throws HttpException, IOException {
if (!request.containsHeader("Accept-Encoding")) {
request.addHeader("Accept-Encoding", "gzip");
}
}
});
代码示例来源:origin: apache/hive
@Override
protected void addHttpAuthHeader(HttpRequest httpRequest, HttpContext httpContext)
throws Exception {
Header basicAuthHeader = authScheme.authenticate(credentials, httpRequest, httpContext);
httpRequest.addHeader(basicAuthHeader);
}
}
代码示例来源: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.containsHeader(HTTP.CONN_DIRECTIVE)) {
// Default policy is to keep connection alive
// whenever possible
request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
}
}
代码示例来源:origin: k9mail/k-9
public static void modifyRequestToAcceptGzipResponse(HttpRequest request) {
Timber.i("Requesting gzipped data");
request.addHeader("Accept-Encoding", "gzip");
}
代码示例来源:origin: mttkay/ignition
@Override
public void process(final HttpRequest request, final HttpContext context) {
// Add header to accept gzip content
if (!request.containsHeader(IgnitedHttp.HEADER_ACCEPT_ENCODING)) {
request.addHeader(IgnitedHttp.HEADER_ACCEPT_ENCODING, IgnitedHttp.ENCODING_GZIP);
}
}
代码示例来源: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: apache/hive
@Override
protected void addHttpAuthHeader(HttpRequest httpRequest, HttpContext httpContext) throws Exception {
try {
// Generate the service ticket for sending to the server.
// Locking ensures the tokens are unique in case of concurrent requests
kerberosLock.lock();
String kerberosAuthHeader = HttpAuthUtils.getKerberosServiceTicket(principal, host, serverHttpUrl, loggedInSubject);
// Set the session key token (Base64 encoded) in the headers
httpRequest.addHeader(HttpAuthUtils.AUTHORIZATION + ": " + HttpAuthUtils.NEGOTIATE + " ", kerberosAuthHeader);
} catch (Exception e) {
throw new HttpException(e.getMessage(), e);
} finally {
kerberosLock.unlock();
}
}
}
代码示例来源: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");
}
// Add default headers
Collection<?> defHeaders = (Collection<?>) request.getParams().getParameter(
ClientPNames.DEFAULT_HEADERS);
if (defHeaders != null) {
for (Object defHeader : defHeaders) {
request.addHeader((Header) defHeader);
}
}
}
代码示例来源:origin: fabric8io/docker-maven-plugin
/**
* Sign a request. Add the headers that authenticate the request.
*
* @param request The request to sign.
* @param credentials The credentials to use when signing.
* @param signingTime The invocation time to use;
*/
void sign(HttpRequest request, AuthConfig credentials, Date signingTime) {
AwsSigner4Request sr = new AwsSigner4Request(region, service, request, signingTime);
if(!request.containsHeader("X-Amz-Date")) {
request.addHeader("X-Amz-Date", sr.getSigningDateTime());
}
request.addHeader("Authorization", task4(sr, credentials));
final String securityToken = credentials.getAuth();
if (StringUtils.isNotEmpty(securityToken)) {
request.addHeader("X-Amz-Security-Token", securityToken);
}
}
代码示例来源: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.containsHeader(HTTP.USER_AGENT)) {
String useragent = HttpProtocolParams.getUserAgent(request.getParams());
if (useragent != null) {
request.addHeader(HTTP.USER_AGENT, useragent);
}
}
}
代码示例来源:origin: apache/hive
httpRequest.addHeader(entry.getKey(), entry.getValue());
cookieHeaderKeyValues = cookieHeaderKeyValues.substring(1);
httpRequest.addHeader("Cookie", cookieHeaderKeyValues);
代码示例来源: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) {
HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
// Do not send the expect header if request body is known to be empty
if (entity != null && entity.getContentLength() != 0) {
ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
if (HttpProtocolParams.useExpectContinue(request.getParams())
&& !ver.lessEquals(HttpVersion.HTTP_1_0)) {
request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
}
}
}
}
代码示例来源:origin: robovm/robovm
HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();
if (entity == null) {
request.addHeader(HTTP.CONTENT_LEN, "0");
return;
"Chunked transfer encoding not allowed for " + ver);
request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
} else {
request.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
request.addHeader(entity.getContentType());
request.addHeader(entity.getContentEncoding());
代码示例来源:origin: robovm/robovm
request.addHeader(HTTP.TARGET_HOST, targethost.toHostString());
代码示例来源:origin: robovm/robovm
request.addHeader(authScheme.authenticate(creds, request));
} catch (AuthenticationException ex) {
if (this.log.isErrorEnabled()) {
代码示例来源:origin: robovm/robovm
request.addHeader(authScheme.authenticate(creds, request));
} catch (AuthenticationException ex) {
if (this.log.isErrorEnabled()) {
内容来源于网络,如有侵权,请联系作者删除!