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