本文整理汇总了Java中com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.HttpConstants类的典型用法代码示例。如果您正苦于以下问题:Java HttpConstants类的具体用法?Java HttpConstants怎么用?Java HttpConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpConstants类属于com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants包,在下文中一共展示了HttpConstants类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: buildUrl
import com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.HttpConstants; //导入依赖的package包/类
/**
* Returns a URL to use to send a message to the data center.
*
* @param gaiaServiceId Gaia service for which the request will be authenticated (when using a
* GoogleLogin token), or {@code null} when using an OAuth2 token.
* @param networkEndpointId network id of the client
*/
private static URL buildUrl(String gaiaServiceId, NetworkEndpointId networkEndpointId)
throws MalformedURLException {
StringBuilder urlBuilder = new StringBuilder();
// Build base URL that targets the inbound request service with the encoded network endpoint
// id.
urlBuilder.append((channelUrlForTest != null) ? channelUrlForTest : HttpConstants.CHANNEL_URL);
urlBuilder.append(HttpConstants.REQUEST_URL);
// TODO: We should be sending a ClientGatewayMessage in the request body
// instead of appending the client's network endpoint id to the request URL. Once we do that, we
// should use a UriBuilder to build up a structured Uri object instead of the brittle string
// concatenation we're doing below.
urlBuilder.append(base64Encode(networkEndpointId.toByteArray()));
// Add query parameter indicating the service to authenticate against
if (gaiaServiceId != null) {
urlBuilder.append('?');
urlBuilder.append(HttpConstants.SERVICE_PARAMETER);
urlBuilder.append('=');
urlBuilder.append(gaiaServiceId);
}
return new URL(urlBuilder.toString());
}
开发者ID:mogoweb,项目名称:365browser,代码行数:32,代码来源:AndroidMessageSenderService.java
示例2: createUrlConnectionForPost
import com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.HttpConstants; //导入依赖的package包/类
/**
* Returns an {@link HttpURLConnection} to use to POST a message to the data center. Sets
* the content-type and user-agent headers; also sets the echo token header if we have an
* echo token.
*
* @param context Android context
* @param url URL to which to post
* @param authToken auth token to provide in the request header
* @param isOAuth2Token whether the token is an OAuth2 token (vs. a GoogleLogin token)
*/
public static HttpURLConnection createUrlConnectionForPost(Context context, URL url,
String authToken, boolean isOAuth2Token) throws IOException {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
connection.setRequestMethod("POST");
} catch (ProtocolException exception) {
throw new RuntimeException("Cannot set request method to POST: " + exception);
}
connection.setDoOutput(true);
if (isOAuth2Token) {
connection.setRequestProperty("Authorization", "Bearer " + authToken);
} else {
connection.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken);
}
connection.setRequestProperty("Content-Type", HttpConstants.PROTO_CONTENT_TYPE);
connection.setRequestProperty("User-Agent",
context.getApplicationInfo().className + "(" + Build.VERSION.RELEASE + ")");
String echoToken = AndroidChannelPreferences.getEchoToken(context);
if (echoToken != null) {
// If we have a token to echo to the server, echo it.
connection.setRequestProperty(HttpConstants.ECHO_HEADER, echoToken);
}
return connection;
}
开发者ID:morristech,项目名称:android-chromium,代码行数:36,代码来源:AndroidMessageSenderService.java
示例3: createUrlConnectionForPost
import com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.HttpConstants; //导入依赖的package包/类
/**
* Returns an {@link HttpURLConnection} to use to POST a message to the data center. Sets
* the content-type and user-agent headers; also sets the echo token header if we have an
* echo token.
*
* @param context Android context
* @param url URL to which to post
* @param authToken auth token to provide in the request header
* @param isOAuth2Token whether the token is an OAuth2 token (vs. a GoogleLogin token)
*/
public static HttpURLConnection createUrlConnectionForPost(
Context context, URL url, String authToken, boolean isOAuth2Token) throws IOException {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
connection.setRequestMethod("POST");
} catch (ProtocolException exception) {
throw new RuntimeException("Cannot set request method to POST", exception);
}
connection.setDoOutput(true);
if (isOAuth2Token) {
connection.setRequestProperty("Authorization", "Bearer " + authToken);
} else {
connection.setRequestProperty("Authorization", "GoogleLogin auth=" + authToken);
}
connection.setRequestProperty("Content-Type", HttpConstants.PROTO_CONTENT_TYPE);
connection.setRequestProperty(
"User-Agent", context.getApplicationInfo().className + "(" + Build.VERSION.RELEASE + ")");
String echoToken = AndroidChannelPreferences.getEchoToken(context);
if (echoToken != null) {
// If we have a token to echo to the server, echo it.
connection.setRequestProperty(HttpConstants.ECHO_HEADER, echoToken);
}
return connection;
}
开发者ID:mogoweb,项目名称:365browser,代码行数:37,代码来源:AndroidMessageSenderService.java
注:本文中的com.google.ipc.invalidation.ticl.android2.channel.AndroidChannelConstants.HttpConstants类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论