本文整理汇总了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());
}
示例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;
}
示例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;
}