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


Java HttpMessage.setHeader方法代码示例

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


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

示例1: setHeaders

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
/**
 * Sets the headers of an HTTP request necessary to execute. 
 * 
 * @param httpMessage   The HTTP request to add the basic headers.
 * @param headers       A map of key-value pairs representing the headers.
 */
public static void setHeaders( HttpMessage httpMessage, Map<String,String> headers )
{
	if( headers == null )
	{
		httpMessage.setHeader( "Accept-Language", "en-us,en;q=0.5" );
		return;
	} 
	else if( !headers.containsKey( "Accept-Language" ) ) 
	{
		headers.put( "Accept-Language", "en-us,en;q=0.5" );
	}
	
	for( Map.Entry<String, String> entry : headers.entrySet() )
	{
		httpMessage.setHeader( entry.getKey(), entry.getValue() );
	}
}
 
开发者ID:jacksonicson,项目名称:rain,代码行数:24,代码来源:HttpTransport.java

示例2: setHeaders

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
/**
 * @param message
 * @param headers
 */
private void setHeaders(HttpMessage message, Map<String, String> headers) {
    if (headers == null)
        return;
    for (Entry<String, String> entry : headers.entrySet()) {
        message.setHeader(entry.getKey(), entry.getValue().toString());
    }
}
 
开发者ID:modymapp,项目名称:modym-client-java,代码行数:12,代码来源:ModymApiTransport.java

示例3: setHeaders

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
/**
 * 设置Http头部,同时添加上公共的类型,长连接,COS SDK标识
 * 
 * @param message HTTP消息
 * @param headers 用户额外添加的HTTP头部
 */
private void setHeaders(HttpMessage message, Map<String, String> headers) {
    message.setHeader(RequestHeaderKey.ACCEPT, RequestHeaderValue.Accept.ALL);
    message.setHeader(RequestHeaderKey.CONNECTION, RequestHeaderValue.Connection.KEEP_ALIVE);
    message.setHeader(RequestHeaderKey.USER_AGENT, this.config.getUserAgent());

    if (headers != null) {
        for (String headerKey : headers.keySet()) {
            message.setHeader(headerKey, headers.get(headerKey));
        }
    }
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v4,代码行数:18,代码来源:DefaultCosHttpClient.java

示例4: setHeaders

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
private static void setHeaders(HttpMessage httpMessage, Map<String, String> headers) {
    if (headers != null) {
        Iterator<Map.Entry<String, String>> entries = headers.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<String, String> entry = entries.next();
            httpMessage.setHeader(entry.getKey(), entry.getValue());
        }
    }
}
 
开发者ID:thewaychung,项目名称:ambry-client,代码行数:10,代码来源:HttpHelper.java

示例5: setHeaders

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
/**
 * 设置Http头部,同时添加上公共的类型,长连接,COS SDK标识
 * 
 * @param message
 *            HTTP消息
 * @param headers
 *            用户额外添加的HTTP头部
 */
private void setHeaders(HttpMessage message, Map<String, String> headers) {
	message.setHeader(RequestHeaderKey.ACCEPT, RequestHeaderValue.Accept.ALL);
	message.setHeader(RequestHeaderKey.CONNECTION, RequestHeaderValue.Connection.KEEP_ALIVE);
	message.setHeader(RequestHeaderKey.USER_AGENT, this.config.getUserAgent());

	if (headers != null) {
		for (String headerKey : headers.keySet()) {
			message.setHeader(headerKey, headers.get(headerKey));
		}
	}
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk,代码行数:20,代码来源:DefaultCosHttpClient.java

示例6: setHeaders

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
private void setHeaders(HttpMessage httpMessage,
        Map<String, String> headers) {
    if (headers == null) {
        return;
    }

    Set<Entry<String, String>> entrys = headers.entrySet();
    for (Entry<String, String> entry : entrys) {
        // 对于HttpClient中已经设置过的header(例如User-Agent), 会被新的header覆盖
        httpMessage.setHeader(entry.getKey(), entry.getValue());
    }
}
 
开发者ID:ufologist,项目名称:HttpToolbox,代码行数:13,代码来源:HttpClientExample.java

示例7: transferFirstHeader

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
protected void transferFirstHeader(final String headerName, final String destName, final HttpMessage origin, final HttpMessage dest) {
	Header header = origin.getFirstHeader(headerName);
	if (header!=null)
		dest.setHeader(destName, header.getValue());
}
 
开发者ID:Coffeeboys,项目名称:RenewPass,代码行数:6,代码来源:InMemoryCacheEntry.java

示例8: writeContentTypeIfNeeded

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
private void writeContentTypeIfNeeded(Request request, HttpMessage httpMessage) {
	if (!"".equals(request.getBody())) {
		httpMessage.setHeader("Content-Type", "application/json");
	}
}
 
开发者ID:sendgrid,项目名称:java-http-client,代码行数:6,代码来源:Client.java

示例9: setUserAgent

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
private static void setUserAgent(HttpMessage hm, String useragent) {
       if(useragent!=null)hm.setHeader("User-Agent",useragent);
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:4,代码来源:HTTPEngine4Impl.java

示例10: setContentType

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
private static void setContentType(HttpMessage hm, String charset) {
	if(charset!=null) hm.setHeader("Content-type", "text/html; charset="+charset);
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:4,代码来源:HTTPEngine4Impl.java

示例11: setIntHeader

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
public static void setIntHeader(HttpMessage message, String name, int value) {
    message.setHeader(name, String.valueOf(value));
}
 
开发者ID:jle,项目名称:andy,代码行数:4,代码来源:HttpHeaders.java

示例12: setHost

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
public static void setHost(HttpMessage message, String host) {
    message.setHeader(Names.HOST, host);
}
 
开发者ID:jle,项目名称:andy,代码行数:4,代码来源:HttpHeaders.java

示例13: setKeepAlive

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
/**
 * Sets the value of the {@code "Connection"} header depending on the
 * protocol version of the specified message.  This method sets or removes
 * the {@code "Connection"} header depending on what the default keep alive
 * mode of the message's protocol version is, as specified by
 * {@link HttpVersion#isKeepAliveDefault()}.
 * <ul>
 * <li>If the connection is kept alive by default:
 *     <ul>
 *     <li>set to {@code "close"} if {@code keepAlive} is {@code false}.</li>
 *     <li>remove otherwise.</li>
 *     </ul></li>
 * <li>If the connection is closed by default:
 *     <ul>
 *     <li>set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.</li>
 *     <li>remove otherwise.</li>
 *     </ul></li>
 * </ul>
 */
public static void setKeepAlive(HttpMessage message, boolean keepAlive) {
    final ProtocolVersion version = message.getProtocolVersion();
    if (HttpVersion.valueOf(version.toString()).isKeepAliveDefault()) {
        if (keepAlive) {
            message.removeHeaders(Names.CONNECTION);
        } else {
            message.setHeader(Names.CONNECTION, Values.CLOSE);
        }
    } else {
        if (keepAlive) {
            message.setHeader(Names.CONNECTION, Values.KEEP_ALIVE);
        } else {
            message.removeHeaders(Names.CONNECTION);
        }
    }
}
 
开发者ID:jle,项目名称:andy,代码行数:36,代码来源:HttpHeaders.java

示例14: setContentLength

import org.apache.http.HttpMessage; //导入方法依赖的package包/类
/**
 * Sets the {@code "Content-Length"} header.
 */
public static void setContentLength(HttpMessage message, long length) {
    message.setHeader(Names.CONTENT_LENGTH, String.valueOf(length));
}
 
开发者ID:jle,项目名称:andy,代码行数:7,代码来源:HttpHeaders.java


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