當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestBuilder.setHeader方法代碼示例

本文整理匯總了Java中org.apache.http.client.methods.RequestBuilder.setHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestBuilder.setHeader方法的具體用法?Java RequestBuilder.setHeader怎麽用?Java RequestBuilder.setHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.client.methods.RequestBuilder的用法示例。


在下文中一共展示了RequestBuilder.setHeader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addHeaders

import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
protected RequestBuilder addHeaders(RequestBuilder requestBuilder) {
    if (deliveryOptions.getProductionApiKey() != null) {
        requestBuilder.setHeader(
                HttpHeaders.AUTHORIZATION, String.format("Bearer %s", deliveryOptions.getProductionApiKey())
        );
    } else if (deliveryOptions.isUsePreviewApi()) {
        requestBuilder.setHeader(
                HttpHeaders.AUTHORIZATION, String.format("Bearer %s", deliveryOptions.getPreviewApiKey())
        );
    }
    if (deliveryOptions.isWaitForLoadingNewContent()) {
        requestBuilder.setHeader(
                "X-KC-Wait-For-Loading-New-Content", "true"
        );
    }
    requestBuilder.setHeader(HttpHeaders.ACCEPT, "application/json");
    requestBuilder.setHeader("X-KC-SDKID", SDK_ID);
    return requestBuilder;
}
 
開發者ID:Kentico,項目名稱:delivery-sdk-java,代碼行數:20,代碼來源:DeliveryClient.java

示例2: toSpanTextMap

import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
@Override
protected SpanTextMap toSpanTextMap(final RequestBuilder context) {
	return new SpanTextMap() {
		@Override public Iterator<Map.Entry<String, String>> iterator() {
			Map<String, String> map = new HashMap<>();
			for (Header header : context.build().getAllHeaders()) {
				map.put(header.getName(), header.getValue());
			}
			return map.entrySet().iterator();
		}

		@Override public void put(String key, String value) {
			context.setHeader(key, value);
		}
	};
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-sleuth,代碼行數:17,代碼來源:ApacheHttpClientRibbonRequestCustomizer.java

示例3: generateHttpRequest

import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
protected HttpUriRequest generateHttpRequest(Site site,Request request,HttpHost proxy){
	RequestBuilder requestBuilder = selectRequestMethod(request).setUri(request.getUrl());
       if (site.getHeaders() != null) {
           for (Map.Entry<String, String> headerEntry : site.getHeaders().entrySet()) {
               requestBuilder.setHeader(headerEntry.getKey(), headerEntry.getValue());
           }
       }
       RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
       if (site != null) {
           requestConfigBuilder.setConnectionRequestTimeout(site.getTimeout())
                   .setSocketTimeout(site.getTimeout())
                   .setConnectTimeout(site.getTimeout())
                   .setCookieSpec(CookieSpecs.STANDARD);
       }

       if (proxy != null) {
           requestConfigBuilder.setProxy(proxy);
       }
       requestBuilder.setConfig(requestConfigBuilder.build());
       HttpUriRequest httpUriRequest = requestBuilder.build();
       if (request.getHeaders() != null && !request.getHeaders().isEmpty()) {
           for (Map.Entry<String, String> header : request.getHeaders().entrySet()) {
               httpUriRequest.setHeader(header.getKey(), header.getValue());
           }
       }
       return httpUriRequest;
}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:28,代碼來源:AbsDownloader.java

示例4: addHttpHeaders

import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
private void addHttpHeaders( RequestBuilder request )
{
    request.setHeader( "MS-Contract-Version", PartnerService.getInstance().getPartnerServiceApiVersion() );
    request.setHeader( "MS-RequestId", this.getRequestId().toString() );
    request.setHeader( "MS-CorrelationId", this.getCorrelationId().toString() );
    request.setHeader( "X-Locale", getLocale() );
    if( PartnerService.getInstance().getPartnerServiceApiVersion() != null && PartnerService.getInstance().getPartnerServiceApiVersion().trim().isEmpty() != true )
    {
    	request.setHeader( "MS-PartnerCenter-Application", PartnerService.getInstance().getApplicationName() );
    }
    request.setHeader( "MS-PartnerCenter-Client", "Partner Center JAVA SDK" );
    request.setHeader( "Authorization", "Bearer " + this.getPartner().getCredentials().getPartnerServiceToken() );
    request.setHeader( "Accept", this.getAccept() );

    if ( request.getEntity() != null )

    {
        request.setHeader( "Content-Type", this.getContentType() );
    }

    if ( this.getAdditionalRequestHeaders() != null )
    {
        for ( KeyValuePair<String, String> header : this.getAdditionalRequestHeaders() )
        {
            request.setHeader( header.getKey(), header.getValue() );
        }
    }
}
 
開發者ID:PartnerCenterSamples,項目名稱:Partner-Center-Java-SDK,代碼行數:29,代碼來源:PartnerServiceProxy.java


注:本文中的org.apache.http.client.methods.RequestBuilder.setHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。