当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequest.addHeader方法代码示例

本文整理汇总了Java中org.apache.http.HttpRequest.addHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.addHeader方法的具体用法?Java HttpRequest.addHeader怎么用?Java HttpRequest.addHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.HttpRequest的用法示例。


在下文中一共展示了HttpRequest.addHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: determineProxy

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
@Override
protected HttpHost determineProxy(HttpHost host, HttpRequest request, HttpContext context) throws HttpException {
    HttpClientContext httpClientContext = HttpClientContext.adapt(context);
    Proxy proxy = proxyPlanner.determineProxy(host, request, context, ipPool, crawlerSession);

    if (proxy == null) {
        return null;
    }
    if (log.isDebugEnabled()) {
        log.debug("{} 当前使用IP为:{}:{}", host.getHostName(), proxy.getIp(), proxy.getPort());
    }
    context.setAttribute(VSCRAWLER_AVPROXY_KEY, proxy);

    if (proxy.getAuthenticationHeaders() != null) {
        for (Header header : proxy.getAuthenticationHeaders()) {
            request.addHeader(header);
        }
    }

    if (StringUtils.isNotEmpty(proxy.getUsername()) && StringUtils.isNotEmpty(proxy.getPassword())) {
        BasicCredentialsProvider credsProvider1 = new BasicCredentialsProvider();
        httpClientContext.setCredentialsProvider(credsProvider1);
        credsProvider1.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));
    }
    return new HttpHost(proxy.getIp(), proxy.getPort());
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:28,代码来源:VSCrawlerRoutePlanner.java

示例2: process

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
public void process(HttpRequest request, HttpContext context) {
    if (!request.containsHeader(AsyncHttpClient.HEADER_ACCEPT_ENCODING)) {
        request.addHeader(AsyncHttpClient.HEADER_ACCEPT_ENCODING, AsyncHttpClient
                .ENCODING_GZIP);
    }
    for (String header : AsyncHttpClient.access$000(this.this$0).keySet()) {
        if (request.containsHeader(header)) {
            Header overwritten = request.getFirstHeader(header);
            Log.d(AsyncHttpClient.LOG_TAG, String.format("Headers were overwritten! (%s | %s)" +
                    " overwrites (%s | %s)", new Object[]{header, AsyncHttpClient.access$000
                    (this.this$0).get(header), overwritten.getName(), overwritten.getValue()}));
            request.removeHeader(overwritten);
        }
        request.addHeader(header, (String) AsyncHttpClient.access$000(this.this$0).get(header));
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:AsyncHttpClient$1.java

示例3: addRequestInformation

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
public static void addRequestInformation(Subsegment subsegment, HttpRequest request, String url) {
    subsegment.setNamespace(Namespace.REMOTE.toString());
    Segment parentSegment = subsegment.getParentSegment();

    TraceHeader header = new TraceHeader(parentSegment.getTraceId(),
                            parentSegment.isSampled() ? subsegment.getId() : null,
                            parentSegment.isSampled() ? SampleDecision.SAMPLED : SampleDecision.NOT_SAMPLED);
    request.addHeader(TraceHeader.HEADER_KEY, header.toString());

    Map<String, Object> requestInformation = new HashMap<>();

    requestInformation.put("url", url);
    requestInformation.put("method", request.getRequestLine().getMethod());

    subsegment.putHttp("request", requestInformation);
}
 
开发者ID:aws,项目名称:aws-xray-sdk-java,代码行数:17,代码来源:TracedHttpClient.java

示例4: process

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }

    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        return;
    }

    // Add default headers
    @SuppressWarnings("unchecked")
    Collection<Header> defHeaders = (Collection<Header>) request.getParams().getParameter(
            ClientPNames.DEFAULT_HEADERS);

    if (defHeaders != null) {
        for (Header defHeader : defHeaders) {
            request.addHeader(defHeader);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:RequestDefaultHeaders.java

示例5: process

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    if (request == null) {
        throw new IllegalArgumentException("HTTP request may not be null");
    }

    String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        return;
    }

    if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
        // Default policy is to keep connection alive
        // whenever possible
        request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:RequestConnControl.java

示例6: process

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
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);
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:RequestExpectContinue.java

示例7: process

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    if(StringUtils.contains(request.getRequestLine().getUri(), "b2_authorize_account")) {
        // Skip setting token for
        if(log.isDebugEnabled()) {
            log.debug("Skip setting token in b2_authorize_account");
        }
        return;
    }
    switch(request.getRequestLine().getMethod()) {
        case "POST":
            // Do not override Authorization header for upload requests with upload URL token
            break;
        default:
            if(StringUtils.isNotBlank(authorizationToken)) {
                request.removeHeaders(HttpHeaders.AUTHORIZATION);
                request.addHeader(HttpHeaders.AUTHORIZATION, authorizationToken);
            }
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:21,代码来源:B2ErrorResponseInterceptor.java

示例8: doGET

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
public HttpResponse doGET(URI url) throws IOException, HttpException {
  String uri = url.getRawPath() + (url.getRawQuery() != null ? "?" + url.getRawQuery() : "");
  HttpRequest request = new BasicHttpRequest("GET", uri);
  String hostHeader = (url.getPort() == 0 || url.getPort() == 80)
      ? url.getHost() : (url.getHost() + ":" + url.getPort());
  request.addHeader("Host", hostHeader);
  return execute(request);
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:9,代码来源:RequestExecutorBasedClientInstrumentationTest.java

示例9: process

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    if(StringUtils.isNotBlank(token)) {
        request.removeHeaders(SDSSession.SDS_AUTH_TOKEN_HEADER);
        request.addHeader(SDSSession.SDS_AUTH_TOKEN_HEADER, token);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:8,代码来源:SDSErrorResponseInterceptor.java

示例10: setAuthorizationHeader

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
private void setAuthorizationHeader( HttpRequest requestMethod )
{
	/* First try basic auth */
	String authHeader = getAuthenticationHeaderBasic( );
	/* If null, try Oauth */
	if ( authHeader == null )
	{
		authHeader = getAuthenticationHeaderBearer( );
	}
	/* Set header if not null, otherwise don't set header */
	if ( authHeader != null )
	{
		requestMethod.addHeader( "Authorization", authHeader );
	}
}
 
开发者ID:ApinautenGmbH,项目名称:integration-test-helper,代码行数:16,代码来源:AomHttpClient.java

示例11: tryCloseConnection

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
private void tryCloseConnection(HttpRequest request) {
	Header[] headers = request.getHeaders("Connection");
	if (headers != null && headers.length > 0) {
		for (Header h : headers) {
			request.removeHeader(h);
		}
	}

	request.addHeader("Connection", "close");
}
 
开发者ID:aliyun,项目名称:HiTSDB-Client,代码行数:11,代码来源:HiTSDBHttpAsyncCallbackExecutor.java

示例12: execute

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
@Override
public HttpResponse execute(final HttpRequest request, final HttpClientConnection conn, final HttpContext context)
        throws IOException, HttpException {
    if(!request.containsHeader(HttpHeaders.USER_AGENT)) {
        request.addHeader(new BasicHeader(HttpHeaders.USER_AGENT, useragentProvider.get()));
    }
    return super.execute(request, conn, context);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:9,代码来源:LoggingHttpRequestExecutor.java

示例13: process

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
@Override
public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {
	final String credentials = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8).trim();
	httpRequest.addHeader(HttpHeaders.AUTHORIZATION, credentials);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:6,代码来源:ResourceBasedAuthorizationInterceptor.java

示例14: modifyRequestToAcceptGzipResponse

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
public static void modifyRequestToAcceptGzipResponse(HttpRequest request) {
    Timber.i("Requesting gzipped data");
    request.addHeader("Accept-Encoding", "gzip");
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:5,代码来源:QMailHttpClient.java

示例15: process

import org.apache.http.HttpRequest; //导入方法依赖的package包/类
public void process(HttpRequest request, HttpContext context) {
    if (!request.containsHeader("Accept-Encoding")) {
        request.addHeader("Accept-Encoding", "gzip");
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:6,代码来源:RestClient.java


注:本文中的org.apache.http.HttpRequest.addHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。