本文整理汇总了Java中org.apache.http.message.AbstractHttpMessage.addHeader方法的典型用法代码示例。如果您正苦于以下问题:Java AbstractHttpMessage.addHeader方法的具体用法?Java AbstractHttpMessage.addHeader怎么用?Java AbstractHttpMessage.addHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.message.AbstractHttpMessage
的用法示例。
在下文中一共展示了AbstractHttpMessage.addHeader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addUserAgentHeader
import org.apache.http.message.AbstractHttpMessage; //导入方法依赖的package包/类
public static void addUserAgentHeader(Context context, AbstractHttpMessage request) {
String systemUserAgent = System.getProperty("http.agent");
String customUserAgent = "";
try {
customUserAgent = new StringBuilder().append("p2psafety/")
// add app version
.append(context.getPackageManager()
.getPackageInfo(context.getPackageName(), 0).versionName).append(" ")
// split davlik machine version
.append(systemUserAgent.substring(systemUserAgent.indexOf('(', 0),
systemUserAgent.length())).toString();
request.addHeader(new BasicHeader("User-Agent", customUserAgent));
Log.i("getUserAgent", customUserAgent);
} catch (PackageManager.NameNotFoundException e) {
request.addHeader(new BasicHeader("User-Agent", systemUserAgent));
}
}
示例2: applyHeaders
import org.apache.http.message.AbstractHttpMessage; //导入方法依赖的package包/类
static void applyHeaders(Configuration config, AbstractHttpMessage message, String httpMethod, String urlPath,
String contentType, String acceptType)
{
if (config.getTcToken() != null)
{
message.addHeader("authorization", "TC-Token " + config.getTcToken());
}
else
{
Long ts = System.currentTimeMillis() / 1000L;
String sig = getSignature(ts, httpMethod, urlPath, null);
String hmacSig = getHmacSha256Signature(sig, config.getTcApiUserSecretKey());
String auth = getAuthorizationText(config, hmacSig);
message.addHeader("timestamp", "" + ts);
message.addHeader("authorization", auth);
}
message.addHeader("Accept", acceptType);
if (contentType != null)
{
message.addHeader("Content-Type", contentType);
}
}
示例3: httpAddons
import org.apache.http.message.AbstractHttpMessage; //导入方法依赖的package包/类
protected void httpAddons(final AbstractHttpMessage httpMessage,
final Event event) {
if (headers != null) {
for (String headerKey : headers.keySet()) {
httpMessage.addHeader(headerKey, headers.get(headerKey));
}
}
}
示例4: addAuthHeader
import org.apache.http.message.AbstractHttpMessage; //导入方法依赖的package包/类
private static AbstractHttpMessage addAuthHeader(Context context, AbstractHttpMessage request) {
request.addHeader(new BasicHeader("Authorization", new StringBuilder().append("ApiKey ")
.append(Prefs.getApiUsername(context)).append(":")
.append(Prefs.getApiKey(context)).toString()));
Log.i("addAuthHeader", Prefs.getApiUsername(context) + ":" + Prefs.getApiKey(context));
return request;
}
示例5: addInternalHeaders
import org.apache.http.message.AbstractHttpMessage; //导入方法依赖的package包/类
/**
* Sets headers to the http message.
*
* @param httpMsg http message to set headers for
*/
private void addInternalHeaders(AbstractHttpMessage httpMsg) {
if (headers.isEmpty()) {
return;
}
final Set<String> keySet = headers.keySet();
for (final String key : keySet) {
final List<String> values = headers.get(key);
for (final String value : values) {
httpMsg.addHeader(key, value);
}
}
}
示例6: setExtraHeaders
import org.apache.http.message.AbstractHttpMessage; //导入方法依赖的package包/类
@Override
protected void setExtraHeaders(AbstractHttpMessage httpMessage) {
httpMessage.addHeader("key", "value");
}
示例7: setHeaders
import org.apache.http.message.AbstractHttpMessage; //导入方法依赖的package包/类
protected static void setHeaders(AbstractHttpMessage request) {
request.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
request.addHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.toString());
}