मैं GZIPInputStream
का उपयोग करके एक GZIPed HTTP प्रतिक्रिया को असंप्रेषित करने का प्रयास कर रहा हूं। हालांकि मैं हमेशा एक ही अपवाद है जब मैं धारा पढ़ने की कोशिश: java.util.zip.ZipException: invalid bit length repeat
जावा में GZIPed HTTP प्रतिक्रिया को असंप्रेषित करें
मेरे HTTP अनुरोध हेडर: HTTP प्रतिक्रिया हेडर के अंत में
GET www.myurl.com HTTP/1.0\r\n
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2) Gecko/20100115 Firefox/3.6\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3\r\n
Accept-Encoding: gzip,deflate\r\n
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7\r\n
Keep-Alive: 115\r\n
Connection: keep-alive\r\n
X-Requested-With: XMLHttpRequest\r\n
Cookie: Some Cookies\r\n\r\n
, मैं path=/Content-Encoding: gzip
मिलता है, gziped प्रतिक्रिया के बाद ।
मैंने कोशिश की 2 समानता कोड को विस्तारित करने में:
अद्यतन: निम्नलिखित कोड में, tBytes = (the string after 'path=/Content-Encoding: gzip').getBytes();
GZIPInputStream gzip = new GZIPInputStream (new ByteArrayInputStream (tBytes));
StringBuffer szBuffer = new StringBuffer();
byte tByte [] = new byte [1024];
while (true)
{
int iLength = gzip.read (tByte, 0, 1024); // <-- Error comes here
if (iLength < 0)
break;
szBuffer.append (new String (tByte, 0, iLength));
}
और यह एक है कि मैं इस मंच पर मिल:
InputStream gzipStream = new GZIPInputStream (new ByteArrayInputStream (tBytes));
Reader decoder = new InputStreamReader (gzipStream, "UTF-8");//<- I tried ISO-8859-1 and get the same exception
BufferedReader buffered = new BufferedReader (decoder);
मुझे लगता है कि यह एक एन्कोडिंग त्रुटि है।
सादर,
bill0ute
हाय विम। आपके उत्तर के लिए धन्यवाद। मैंने यह संदेश बताने के लिए संदेश अपडेट किया है कि मुझे टीबीइट्स कैसे प्राप्त होते हैं। मुझे नहीं लगता कि प्रतिक्रिया खराब हो गई है क्योंकि सामग्री-लंबाई शीर्षलेख है। लेकिन मुझे यकीन नहीं। बिल 0्यूट – bill0ute
हाय विम। मैं HttpClient पैकेज का उपयोग करने की कोशिश कर रहा हूं लेकिन मुझे जावा डॉक नहीं मिल रहा है। मुझे केवल उदाहरण मिलते हैं। क्या आप मुझे सॉकेट से कनेक्ट करने का एक छोटा सा उदाहरण दे सकते हैं और अनुरोध प्राप्त कर सकते हैं? धन्यवाद – bill0ute
ट्यूटोरियल पर एक नज़र डालें, HTTP GET के लिए प्रतिक्रिया निकाय प्राप्त करने के लिए यह एक साधारण उदाहरण है: http://hc.apache.org/httpclient-3.x/tutorial.html अपने मामले में आप चाहेंगे प्रक्रिया 'प्रतिक्रिया बॉडी' की तरह अब आप 'tyytes' को संसाधित करते हैं। –