本文整理汇总了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() );
}
}
示例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());
}
}
示例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));
}
}
}
示例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());
}
}
}
示例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));
}
}
}
示例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());
}
}
示例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());
}
示例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");
}
}
示例9: setUserAgent
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
private static void setUserAgent(HttpMessage hm, String useragent) {
if(useragent!=null)hm.setHeader("User-Agent",useragent);
}
示例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);
}
示例11: setIntHeader
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
public static void setIntHeader(HttpMessage message, String name, int value) {
message.setHeader(name, String.valueOf(value));
}
示例12: setHost
import org.apache.http.HttpMessage; //导入方法依赖的package包/类
public static void setHost(HttpMessage message, String host) {
message.setHeader(Names.HOST, host);
}
示例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);
}
}
}
示例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));
}