Acesso a uma URL [RESOLVIDO]

9 respostas
M

Estou tentando acessar uma URL, usando:

// Create a URL for the desired page
			URL url = new URL("http://java.sun.com:80/index.html");
					 
// Read all the text returned by the server
			BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
			
			String str;
	
			while ((str = in.readLine()) != null) {
				System.out.println(str);
				
			}

porém aparece a seguinte exceção

Exception in thread "main" java.net.UnknownHostException: java.sun.com
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at sun.net.NetworkClient.doConnect(Unknown Source)
	at sun.net.www.http.HttpClient.openServer(Unknown Source)
	at sun.net.www.http.HttpClient.openServer(Unknown Source)
	at sun.net.www.http.HttpClient.<init>(Unknown Source)
	at sun.net.www.http.HttpClient.New(Unknown Source)
	at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
	at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	at search.Teste1.main(Teste1.java:49)

Alguém tem idéia de como arrumar??

desde já obrigada :wink:

9 Respostas

thiago.correa

Tenteo retirar aquele 80??? Você está numa rede que tenha proxy??!

M

Não surte efeito algum tirar o :80. Estou sim.

thiago.correa

Passei pelo mesmo problema hoje de manhã, veja se ao adicionar essas linhas antes de criar o objeto URL surte efeito

//pegas as propriedades do sistema
      Properties systemProperties = System.getProperties();

      // seta a propriedade proxy
      systemProperties.put("proxyHost","seu_proxy");
      //seta a porta
      systemProperties.put("proxyPort","numero_da_porta");

      //seta o uso do proxy
      systemProperties.put("proxySet","true");
M

Nenhum :frowning:

thiago.correa

e se trocar a URL???! Tente esta

http://java.sun.com/j2se/1.4.2/docs/api/java/net/URL.html

[Edit]
Se você quer acessar o site da sun, ao invés de index.html, use index.jsp.
[/Edit]

M

Aewwwwwwwwwwwwwwwww … deu certo!!! \o/\o/\o/ muitíssimo obrigada :wink:

thiago.correa

Que isso, não se esqueça das estrelinhas eheheheheh!

Acho que não estava dando certo porque a index.html não existe ou porque havia algo que redirecionasse para o index.jsp.

M

Estrelinhas? boeii… =/

thiago.correa

eheheh, deixa para lá!

Criado 10 de abril de 2006
Ultima resposta 10 de abr. de 2006
Respostas 9
Participantes 2