url - Java Load image from URLConnection -


मेरे पास URLConnection है, जो एक वेब पेज को एक्सेस करता है।

  यूआरएल यूआरएल = नया यूआरएल ( "https: // डोमेन"); Con = url.openConnection (); con.setDoOutput (सही);  

फिर मैंने con.setRequestProperty ()

का उपयोग करके सर्वर को कुछ डेटा भेजा है < / p>

 <कोड> स्ट्रिंग headerValue = con.getHeaderField (6);  

मुझे html भी मिलता है और वहां से एक छवि यूआरएल को पार्स करता है। लेकिन यहां एक समस्या है। मैं केवल, सर्वर को वापस कैश डेटा भेजने जब मैं मेरी छवि acces से इस छवि को मिल सकती है।

तो मैं एक नया कनेक्शन

  यूआरएल URL1 = नए URL खोलने ( "Https: // domain / image); URLConnection con1 = url1.openConnection ();  

मैं कुकीज़ को सर्वर पर वापस भेजता हूं con1.setRequestProperty (" cookie ", headerValue );

और अंत में मैं BufferedInputStream का उपयोग कर छवि को प्राप्त करने की कोशिश करता हूं और फिर एक जेलैबल में एक इमाज बना रहा हूं

  BufferedInputStream = new BufferedInputStream (con1.getInputStream) ()); ByteArrayOutputStream byteArrayOut = नए ByteArrayOutputStream (); पूर्णांक ग, जबकि ((ग = in.read ()) = -1) {byteArrayOut.write (ग);}। छवि छवि = Toolkit.getDefaultToolkit () createImage (byteArrayOut.toByteArray ()); label.setIcon (नई ImageIcon (छवि));  

समस्या यह काम नहीं लगता है यह एक और तरीका है एक सर्वर से एक फ़ाइल प्राप्त करने के लिए है। एक यूआरएल कनेक्शन के माध्यम से? आर कोड

<पूर्व> सर्वर ने यूआरएल के लिए एचटीएमपी प्रतिक्रिया कोड भेजा: 400: sun.net पर http://www.protocol.http.HttpURLConnection.getInputStream (अज्ञात स्रोत) पर https: // domain / image। net.www.protocol.https.HttpsURLConnectionImpl.getInputStream (अज्ञात स्रोत)

अग्रिम धन्यवाद

त्रुटि मिली मामला समाप्त। । कुकीज़ स्ट्रिंग विभाजित करने के लिए इस कोड को प्रयुक्त

  स्ट्रिंग अस्थायी = headerValue.substring (0, (len1-17));  

Comments

Popular posts from this blog

wpf - Line breaks and indenting for the XAML of a saved FlowDocument? -

gtk - Python Window Resize -

c# - read full xml file data over tcp -