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


Java HttpRequestBase.addHeader方法代码示例

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


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

示例1: getHttp

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public String getHttp(String url, List<NameValuePair> headers) throws IOException
{
    HttpRequestBase request = new HttpGet(url);

    if (headers != null)
    {
        for (NameValuePair header : headers)
        {
            request.addHeader(header.getName(), header.getValue());
        }
    }

    HttpClient httpClient = HttpClientBuilder.create().build();
    HttpResponse response = httpClient.execute(request);

    HttpEntity entity = response.getEntity();
    if (entity != null)
    {
        return EntityUtils.toString(entity);

    }
    return null;
}
 
开发者ID:TheCookieLab,项目名称:poloniex-api-java,代码行数:24,代码来源:HTTPClient.java

示例2: addHeadersToRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * Configures the headers in the specified Apache HTTP request.
 */
private void addHeadersToRequest(HttpRequestBase httpRequest, SdkHttpFullRequest request) {

    httpRequest.addHeader(HttpHeaders.HOST, getHostHeaderValue(request));


    // Copy over any other headers already in our request
    request.headers().entrySet().stream()
           /*
            * HttpClient4 fills in the Content-Length header and complains if
            * it's already present, so we skip it here. We also skip the Host
            * header to avoid sending it twice, which will interfere with some
            * signing schemes.
            */
           .filter(e -> !IGNORE_HEADERS.contains(e.getKey()))
           .forEach(e -> e.getValue().forEach(h -> httpRequest.addHeader(e.getKey(), h)));

    /* Set content type and encoding */
    if (httpRequest.getHeaders(HttpHeaders.CONTENT_TYPE) == null ||
        httpRequest.getHeaders(HttpHeaders.CONTENT_TYPE).length == 0) {
        httpRequest.addHeader(HttpHeaders.CONTENT_TYPE,
                              "application/x-www-form-urlencoded; " +
                              "charset=" + lowerCase(DEFAULT_ENCODING));
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:28,代码来源:ApacheHttpRequestFactory.java

示例3: getNewRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private HttpRequestBase getNewRequest(String reqMethod, String reqPayload) 
		throws URISyntaxException, UnsupportedEncodingException {
	HttpRequestBase request;
	if(reqMethod.equals(HttpConstants.REQ_METHOD_POST)) {
		HttpPost postRequest = new HttpPost();
		postRequest.setEntity(new StringEntity(reqPayload, ContentType.create(DataFormats.JSON.getMediaType(), Constants.UTF_8)));
		request = postRequest;
	} else {
		throw new IllegalArgumentException(Errors.ARGS_HTTP_METHOD_UNSUPPORTED.getDescription());
	}
	request.setURI(new URI(String.format("%s://%s:%s/", 
				nodeConfig.getProperty(NodeProps.RPC_PROTOCOL.getKey()),
				nodeConfig.getProperty(NodeProps.RPC_HOST.getKey()),
				nodeConfig.getProperty(NodeProps.RPC_PORT.getKey()))));
	String authScheme = nodeConfig.getProperty(NodeProps.HTTP_AUTH_SCHEME.getKey());
	request.addHeader(resolveAuthHeader(authScheme));
	LOG.debug("<< getNewRequest(..): returning a new HTTP '{}' request with target endpoint "
			+ "'{}' and headers '{}'", reqMethod, request.getURI(), request.getAllHeaders());
	return request;
}
 
开发者ID:Roxas240,项目名称:CryptoPayAPI,代码行数:21,代码来源:SimpleHttpClientImpl.java

示例4: performRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public CloseableHttpResponse performRequest(HttpRequestBase request, boolean revalidate) {
    String method = request.getMethod();
    if (revalidate) {
        request.addHeader(HttpHeaders.CACHE_CONTROL, "max-age=0");
    }
    CloseableHttpResponse response;
    try {
        response = executeGetOrHead(request);
    } catch (IOException e) {
        throw new HttpRequestException(String.format("Could not %s '%s'.", method, request.getURI()), e);
    }

    return response;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:15,代码来源:HttpClientHelper.java

示例5: commitHeaders

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
protected void commitHeaders(ClientInvocation request, HttpRequestBase httpMethod) {
  MultivaluedMap<String, String> headers = request.getHeaders().asMap();
  for (Map.Entry<String, List<String>> header : headers.entrySet()) {
    List<String> values = header.getValue();
    for (String value : values) {
      //               System.out.println(String.format("setting %s = %s", header.getKey(), value));
      httpMethod.addHeader(header.getKey(), value);
    }
  }
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:11,代码来源:ApacheHttpClient4Dot3Engine.java

示例6: addAuth

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
@Override
public void addAuth(HttpRequestBase request, CookieStore cookieStore) {
    String basicAuthUnencoded = String.format("%s:%s", username, password);
    String basicAuth = "Basic " + BaseEncoding.base64().encode(basicAuthUnencoded.getBytes());

    request.addHeader("Authorization", basicAuth);
}
 
开发者ID:orshachar,项目名称:known-issue,代码行数:8,代码来源:BasicAuth.java

示例7: executeRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private <R> CompletableFuture<R> executeRequest(final ResponseParser<R> parser, HttpRequestBase request)
        throws IOException, ClientProtocolException
{
    request.addHeader("OCS-APIRequest", "true");
    request.addHeader("Content-Type", "application/x-www-form-urlencoded");
    request.setProtocolVersion(HttpVersion.HTTP_1_1);

    HttpClientContext context = prepareContext();

    CompletableFuture<R> futureResponse = new CompletableFuture<>();
    HttpAsyncClientSingleton.httpclient.execute(request, context, new ResponseCallback<R>(parser, futureResponse));
    return futureResponse;
}
 
开发者ID:a-schild,项目名称:nextcloud-java-api,代码行数:14,代码来源:ConnectorCommon.java

示例8: addHeadersToHttpMethod

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * Pass the user-specified HTTP headers to the Apache HTTP Components
 * method object.
 */
protected void addHeadersToHttpMethod( HttpRequestBase httpMethod ) {

    for (HttpHeader header : requestHeaders) {
        for (String value : header.getValues()) {
            httpMethod.addHeader(header.getKey(), value);
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:13,代码来源:HttpClient.java

示例9: getRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
public HttpRequestBase getRequest(){
	String url = getUrl();
	HttpRequestBase request = getRequest(url);
	if(!headers.isEmpty()){
		for(Entry<String,List<String>> header : headers.entrySet()){
			for(String headerValue : header.getValue()){
				request.addHeader(header.getKey(), headerValue);
			}
		}
	}
	if(entity != null && canHaveEntity()){
		((HttpEntityEnclosingRequest) request).setEntity(entity);
	}
	if(timeoutMs != null || proxy != null){
		Builder builder = RequestConfig.custom();
		builder.setCookieSpec(CookieSpecs.STANDARD);
		if(timeoutMs != null){
			builder.setConnectTimeout(timeoutMs).setConnectionRequestTimeout(timeoutMs).setSocketTimeout(timeoutMs);
		}
		if(proxy != null){
			builder.setProxy(proxy);
		}

		RequestConfig requestConfig = builder.build();
		request.setConfig(requestConfig);
	}
	return request;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:29,代码来源:DatarouterHttpRequest.java

示例10: addCookies

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private void addCookies(HttpRequestBase method, Cookies cookies)
{
	for( ACookie cookie : cookies.send )
	{
		method.addHeader("Cookie", cookie.toString());
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:8,代码来源:HttpServiceImpl.java

示例11: handlerHeader

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * @param header
 * @param httpRequestBase
 */
private void handlerHeader(Map<String, String> header, HttpRequestBase httpRequestBase) {
    if (Check.isNullOrEmpty(header)) {
        return;
    }
    Iterator<String> iterator = header.keySet().iterator();
    while (iterator.hasNext()) {
        String headerName = iterator.next();
        httpRequestBase.addHeader(headerName, header.get(headerName));
    }
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:15,代码来源:AsuraCommonsHttpclient.java

示例12: addAuthHeadersToRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private void addAuthHeadersToRequest(HttpRequestBase request) {
    if (authHeaderProducer == null) {
        return;
    }
    Map<String, String> authHeaders = authHeaderProducer.getAuthHeaders();
    for (String headerName : authHeaders.keySet()) {
        request.addHeader(headerName, authHeaders.get(headerName));
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:10,代码来源:WebServiceClient.java

示例13: addHeadersToRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * Configures the headers in the specified Apache HTTP request.
 */
private void addHeadersToRequest(HttpRequestBase httpRequest, Request<?> request) {

    httpRequest.addHeader(HttpHeaders.HOST, getHostHeaderValue(request.getEndpoint()));

    // Copy over any other headers already in our request
    for (Entry<String, String> entry : request.getHeaders().entrySet()) {
        /*
         * HttpClient4 fills in the Content-Length header and complains if
         * it's already present, so we skip it here. We also skip the Host
         * header to avoid sending it twice, which will interfere with some
         * signing schemes.
         */
        if (!(ignoreHeaders.contains(entry.getKey()))) {
            httpRequest.addHeader(entry.getKey(), entry.getValue());
        }
    }

    /* Set content type and encoding */
    if (httpRequest.getHeaders(HttpHeaders.CONTENT_TYPE) == null || httpRequest
            .getHeaders
                    (HttpHeaders.CONTENT_TYPE).length == 0) {
        httpRequest.addHeader(HttpHeaders.CONTENT_TYPE,
                "application/x-www-form-urlencoded; " +
                        "charset=" + DEFAULT_ENCODING.toLowerCase());
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:30,代码来源:ApacheHttpRequestFactory.java


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