2013-01-22 4 views
0

웹 사이트에 데이터를 자동으로 입력하도록 프로그래밍 된 다음과 같은 간단한 코드가 있습니다. 그러나, 나는 다음과 같은 오류가 발생합니다 : 내가 넷빈즈를 사용하고Java Connection refused

Exception in thread "main" java.net.ConnectException: Connection refused: connect

.

코드 :

import java.io.IOException; 
import java.net.URL; 
import java.util.List; 
import java.util.Scanner; 

import com.gargoylesoftware.htmlunit.Page; 
import com.gargoylesoftware.htmlunit.*; 
import com.gargoylesoftware.htmlunit.html.HtmlAnchor; 
import com.gargoylesoftware.htmlunit.html.HtmlForm; 
import com.gargoylesoftware.htmlunit.html.HtmlPage; 
import com.gargoylesoftware.htmlunit.html.HtmlTable; 
import com.gargoylesoftware.htmlunit.html.HtmlTableRow; 
import com.gargoylesoftware.htmlunit.html.*; 


public class ts { 

    public static void main(String[] args) throws IOException{ 
     final WebClient webClient = new WebClient(); 
     HtmlPage page = (HtmlPage)webClient.getPage(new URL("http://rise4fun.com/QuickCode")); 
     final HtmlForm form = (HtmlForm)page.getFormsByName("form1").get(0); 
     final HtmlInput inp = form.getInputByName("SourceBox"); 
     inp.setValueAttribute("24.9.2011 | 24 Sep 2011\n8/15/2010"); 
     HtmlSubmitInput sub=(HtmlSubmitInput) page.getHtmlElementById("AskButton"); 
     page = (HtmlPage)sub.submit(); 
     final String pageAsText = page.asText(); 
     HtmlElement out=page.getHtmlElementById("OutputBox"); 
     System.out.println(out.asText()); 

    } 

} 
+0

있습니까? – Swapnil

+0

@ Swapnil- 예, URL에 액세스 할 수 있습니다. – user1628340

답변

1

지금 당신이 방화벽 뒤에 걸 알고 있기 때문에, Java 코드는 인터넷에 액세스 할 수 있습니다 프록시를 정의 할 수 있습니다.

URL url = new URL("http://rise4fun.com/QuickCode"); 
System.setProperty("http.proxyHost", proxy); 
System.setProperty("http.proxyPort", proxyPort); 
URLConnection connection = url.openConnection(); 

프록시 코딩의 또 다른 방법은 다음과 같습니다 그렇지 않으면 URL에 액세스 할 수

URL url = new URL("http://rise4fun.com/QuickCode"); 
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy ip", 8080)); 
URLConnection connection = url.openConnection(proxy); 
+0

도움이되지 않습니다 ... 전혀 웹 사이트에 액세스 할 수 없습니다. – user1628340

+0

방화벽을 사용하고 있습니까? –

+0

아니요, 방화벽을 통해 Netbeans를 허용했습니다. – user1628340