You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Divakar Satyanarayan <Di...@mascotsystems.com> on 2003/01/31 13:32:05 UTC

java.net.UnknownHostException

Hi,

 I am using HTTPConnection to get a connection to an URL. It works fine when
I give just the IP address but when I specify the full path it gives me
following exception

java.net.UnknownHostException: 201.173.335.213/xxxx/xxxxx
        at java.net.InetAddress.getAllByName0(InetAddress.java:571)
        at java.net.InetAddress.getAllByName0(InetAddress.java:540)
        at java.net.InetAddress.getByName(InetAddress.java:472)
        at java.net.Socket.<init>(Socket.java:100)
        at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSo
cket(DefaultProtocolSocketFactory.java:104)
        at
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:488)
        at TrialConnectionClient.main(TrialConnectionClient.java:237).

 What am I missing ? I've pasted the code

			HttpConnection oHttpConnection = new
HttpConnection(strURL,440); 

			logMessage("Connected before"+
oHttpConnection.isOpen() );
			
			logMessage("Connected before"+
oHttpConnection.getProxyHost());

			logMessage("Connected before"+
oHttpConnection.getPort());	 
			 
			oHttpConnection.open();

			logMessage("Connected after"+
oHttpConnection.isOpen() );
			
			RequestOutputStream oRequestOutputStream = new
RequestOutputStream(oHttpConnection.getRequestOutputStream(),false);
			
			logMessage("Output Stream ");

			strXml = "inputXml="+sbInputXML.toString(); 

			oRequestOutputStream.println(strXml); 
			//oRequestOutputStream.close();
			
			logMessage(" Input Stream ");
			
			
			
			BufferedReader oBufferedReader = new
BufferedReader(new
InputStreamReader(oHttpConnection.getResponseInputStream()));
			
			logMessage("Opening the input Stream");
			
			String line;
			
			System.out.println(System.currentTimeMillis());

			logMessage("Buffered Input starting to read");

			while ((line = oBufferedReader.readLine()) != null)
			{
				System.out.println(line);
				sbXMLText.append(line + "\n");
			}
		


> Regards,
> Divakar
> ___________________________
> DIVAKAR SATYANARAYAN
> +91-80-5521701-6 Ext : 1018
> 
> 
> 
> 
DISCLAIMER: Information contained and transmitted by this E-MAIL is
proprietary to Mascot Systems Limited and is intended for use only by the
individual or entity to which it is addressed, and may contain information
that is privileged, confidential or exempt from disclosure under applicable
law. If this is a forwarded message, the content of this E-MAIL may not have
been sent with the authority of the Company. If you are not the intended
recipient, an agent of the intended recipient or a person responsible for
delivering the information to the named recipient, you are notified that any
use, distribution, transmission, printing, copying or dissemination of this
information in any way or in any manner is strictly prohibited. If you have
received this communication in error, please delete this mail & notify us
immediately at Mailadmin@mascotsystems.com Before opening attachments,
please scan for viruses. 



Re: java.net.UnknownHostException

Posted by Michael Becke <be...@u.washington.edu>.
Please take a look at the following URL as an example of how to use  
HttpClient to read from a server:

http://cvs.apache.org/viewcvs/jakarta-commons/httpclient/src/examples/ 
BasicAuthenticatonExample.java?rev=1.3&content-type=text/vnd.viewcvs- 
markup

It seems that the problem is that you are attempting to read directly  
from an HttpConnection.  Though this seems logical given how the  
java.net.UrlConnection works, HttpClient handles things a little  
differently.  All posts, gets, etc. are done via HttpMethods like  
PostMethod and GetMethod.  HttpConnection is not meant to be used  
directly.

Mike

On Friday, January 31, 2003, at 07:32 AM, Divakar Satyanarayan wrote:

> Hi,
>
>  I am using HTTPConnection to get a connection to an URL. It works  
> fine when
> I give just the IP address but when I specify the full path it gives me
> following exception
>
> java.net.UnknownHostException: 201.173.335.213/xxxx/xxxxx
>         at java.net.InetAddress.getAllByName0(InetAddress.java:571)
>         at java.net.InetAddress.getAllByName0(InetAddress.java:540)
>         at java.net.InetAddress.getByName(InetAddress.java:472)
>         at java.net.Socket.<init>(Socket.java:100)
>         at
> org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.cre 
> ateSo
> cket(DefaultProtocolSocketFactory.java:104)
>         at
> org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:4 
> 88)
>         at TrialConnectionClient.main(TrialConnectionClient.java:237).
>
>  What am I missing ? I've pasted the code
>
> 			HttpConnection oHttpConnection = new
> HttpConnection(strURL,440);
>
> 			logMessage("Connected before"+
> oHttpConnection.isOpen() );
> 			
> 			logMessage("Connected before"+
> oHttpConnection.getProxyHost());
>
> 			logMessage("Connected before"+
> oHttpConnection.getPort());	
> 			
> 			oHttpConnection.open();
>
> 			logMessage("Connected after"+
> oHttpConnection.isOpen() );
> 			
> 			RequestOutputStream oRequestOutputStream = new
> RequestOutputStream(oHttpConnection.getRequestOutputStream(),false);
> 			
> 			logMessage("Output Stream ");
>
> 			strXml = "inputXml="+sbInputXML.toString();
>
> 			oRequestOutputStream.println(strXml);
> 			//oRequestOutputStream.close();
> 			
> 			logMessage(" Input Stream ");
> 			
> 			
> 			
> 			BufferedReader oBufferedReader = new
> BufferedReader(new
> InputStreamReader(oHttpConnection.getResponseInputStream()));
> 			
> 			logMessage("Opening the input Stream");
> 			
> 			String line;
> 			
> 			System.out.println(System.currentTimeMillis());
>
> 			logMessage("Buffered Input starting to read");
>
> 			while ((line = oBufferedReader.readLine()) != null)
> 			{
> 				System.out.println(line);
> 				sbXMLText.append(line + "\n");
> 			}
> 		
>
>
>> Regards,
>> Divakar
>> ___________________________
>> DIVAKAR SATYANARAYAN
>> +91-80-5521701-6 Ext : 1018
>>
>>
>>
>>
> DISCLAIMER: Information contained and transmitted by this E-MAIL is
> proprietary to Mascot Systems Limited and is intended for use only by  
> the
> individual or entity to which it is addressed, and may contain  
> information
> that is privileged, confidential or exempt from disclosure under  
> applicable
> law. If this is a forwarded message, the content of this E-MAIL may  
> not have
> been sent with the authority of the Company. If you are not the  
> intended
> recipient, an agent of the intended recipient or a person responsible  
> for
> delivering the information to the named recipient, you are notified  
> that any
> use, distribution, transmission, printing, copying or dissemination of  
> this
> information in any way or in any manner is strictly prohibited. If you  
> have
> received this communication in error, please delete this mail & notify  
> us
> immediately at Mailadmin@mascotsystems.com Before opening attachments,
> please scan for viruses.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:  
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:  
> commons-httpclient-dev-help@jakarta.apache.org
>