मूल्य URLConnection.getContentEncoding()
से लौटे URLConnection.getContentEncoding()
/**
* Returns the value of the <code>content-encoding</code> header field.
*
* @return the content encoding of the resource that the URL references,
* or <code>null</code> if not known.
* @see java.net.URLConnection#getHeaderField(java.lang.String)
*/
public String getContentEncoding() {
return getHeaderField("content-encoding");
}
से हैडर Content-Encoding
कोड से मान देता है इसके बजाय, बल्कि एक connection.getContentType()
कर सामग्री प्रकार निकालते हैं और सामग्री प्रकार से चारसेट पुनः प्राप्त करने के । मैं ऐसा करने के तरीके पर एक नमूना कोड ....
String contentType = connection.getContentType();
String[] values = contentType.split(";"); // values.length should be 2
String charset = "";
for (String value : values) {
value = value.trim();
if (value.toLowerCase().startsWith("charset=")) {
charset = value.substring("charset=".length());
}
}
if ("".equals(charset)) {
charset = "UTF-8"; //Assumption
}
स्रोत
2010-10-14 14:33:43
इस संबंधित धागा किसी और मदद कर सकता है: http://stackoverflow.com/questions/9112259/obtaining-response-charset-of-response -to-get-or-post-request – Spoonface
इसके अलावा एक अच्छा कारण कनेक्शन है .getContentEncoding() शून्य देता है: यह http शीर्षलेख का "सामग्री-एन्कोडिंग" फ़ील्ड देता है, जो ** आपको ** देना नहीं है एक चरित्र सेट उदाहरण के लिए इसका उपयोग किया जाना चाहिए यदि प्राप्त डेटा संपीड़ित होता है और आपको डेटा को बदलने के लिए उपयोग करने का तरीका देता है ताकि आप इसे पढ़ सकें। https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11 – jdarthenay