本文整理匯總了Java中org.apache.http.protocol.HTTP.DEFAULT_CONTENT_CHARSET屬性的典型用法代碼示例。如果您正苦於以下問題:Java HTTP.DEFAULT_CONTENT_CHARSET屬性的具體用法?Java HTTP.DEFAULT_CONTENT_CHARSET怎麽用?Java HTTP.DEFAULT_CONTENT_CHARSET使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.http.protocol.HTTP
的用法示例。
在下文中一共展示了HTTP.DEFAULT_CONTENT_CHARSET屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: StringEntity
/**
* Creates a StringEntity with the specified content, MIME type and charset
*
* @param string content to be used. Not {@code null}.
* @param mimeType MIME type to be used. May be {@code null}, in which case the default
* is {@link HTTP#PLAIN_TEXT_TYPE} i.e. "text/plain"
* @param charset character set to be used. May be {@code null}, in which case the default
* is {@link HTTP#DEF_CONTENT_CHARSET} i.e. "ISO-8859-1"
*
* @since 4.1
* @throws IllegalArgumentException if the string parameter is null
*
* @deprecated (4.1.3) use {@link #StringEntity(String, ContentType)}
*/
@Deprecated
public StringEntity(final String string, String mimeType, String charset)
throws UnsupportedEncodingException {
super();
if (string == null) {
throw new IllegalArgumentException("Source string may not be null");
}
if (mimeType == null) {
mimeType = HTTP.PLAIN_TEXT_TYPE;
}
if (charset == null) {
charset = HTTP.DEFAULT_CONTENT_CHARSET;
}
this.content = string.getBytes(charset);
setContentType(mimeType + HTTP.CHARSET_PARAM + charset);
}
示例2: parseCharset
/**
* Returns the charset specified in the Content-Type of this header,
* or the HTTP default (ISO-8859-1) if none can be found.
*/
public static String parseCharset(Map<String, String> headers) {
String contentType = headers.get(HTTP.CONTENT_TYPE);
if (contentType != null) {
String[] params = contentType.split(";");
for (int i = 1; i < params.length; i++) {
String[] pair = params[i].trim().split("=");
if (pair.length == 2) {
if (pair[0].equals("charset")) {
return pair[1];
}
}
}
}
return HTTP.DEFAULT_CONTENT_CHARSET;
}