URL Connection I/O Exception thrown
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Karthikeyan_Radhakrishna
Posted On:   Monday, May 12, 2003 04:14 AM

I tried connecting to a url. But the code throws an I/O exception, while getting the an OutputStream. I have given the coding below. ************************************************************ URLConnection urlconnection = url.openConnection(); urlconnection.setDoInput(true); urlconnection.setDoOutput(true); urlconnection.setUseCaches(false); urlconnection.setRequestProperty("Content-Type", "text/html"); urlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); urlconnection.setRequestProperty("User-Agent", "MPG Version 2.01"); urlconn   More>>

I tried connecting to a url. But the code throws an I/O exception, while getting the an OutputStream. I have given the coding below.


************************************************************
URLConnection urlconnection = url.openConnection();

urlconnection.setDoInput(true);

urlconnection.setDoOutput(true);


urlconnection.setUseCaches(false);


urlconnection.setRequestProperty("Content-Type", "text/html");


urlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");


urlconnection.setRequestProperty("User-Agent", "MPG Version 2.01");


urlconnection.setRequestProperty("Timeout", "30");


System.out.println("Here I am");


DataOutputStream dataoutputstream = new DataOutputStream(urlconnection.getOutputStream());


System.out.println("Data output Stream "+dataoutputstream);


************************************************************

   <<Less

Re: URL Connection I/O Exception thrown

Posted By:   Laurent_Mihalkovic  
Posted On:   Tuesday, June 10, 2003 05:33 PM

Next time, you may want to include the text of the error message. This is very helpfull for the people who try to answer the questions on this forum. Java exceptions are mostly very well designed, and in my experience reading them carefully very often leads to the answer.

aside from that, DataOutputStream is not for reading data. It is for writing data...

I suggest you get a bit more familiar with the direction of the various streams, as well as their global functionalities (buffered versus not, etc).

hope this helps
laurent

About | Sitemap | Contact