當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。