이 시도 감사 :
public static String getURLData(String url) {
// creates a StringBuilder to store the data
StringBuilder out = new StringBuilder();
try {
// creating the URL
URL u = new URL(url);
// openning a connection
URLConnection uCon = u.openConnection();
// getting the connection's input stream
InputStream in = uCon.getInputStream();
// a buffer to store the data
byte[] buffer = new byte[2048];
// try to insert data in the buffer until there is data to be read
while (in.read(buffer) != -1) {
// storing data...
out.append(new String(buffer));
}
// closing the input stream
in.close();
// exceptions...
} catch (MalformedURLException exc) {
exc.printStackTrace();
} catch (IOException exc) {
exc.printStackTrace();
} catch (SecurityException exc) {
exc.printStackTrace();
} catch (IllegalArgumentException exc) {
exc.printStackTrace();
} catch (UnsupportedOperationException exc) {
exc.printStackTrace();
}
// returning data
return out.toString();
}
당신이 인증 할 필요가 있기 때문에 당신이 몇 가지 더 많은 작업을 수행해야합니다 프록시로 작업해야하는 경우
. 그래서, 당신은 브라우저처럼 작동하는 클라이언트를 원하는 경우 서버가 클라이언트를 알리는 행동을해야하는 경우
How do I make HttpURLConnection use a proxy?
, 당신은 지금 Apache HttpComponentes
에서 HttpClient를 시도 할 수 있습니다 : 여기 당신은 그것에 대해 뭔가를 읽을 수 있습니다 당신은 당신 자신의 서버를 만들고 소켓으로 작업하는 것과 같은 또 다른 접근법을 사용해야 할 것이다. 일반 브라우저로 작업하는 경우 웹 소켓을 사용할 수는 있지만 그렇지 않은 것 같습니다.
'http : // tomcat-location : 8180/myContext'가 반환하는 것을 읽으시겠습니까? – davidbuzatto
예, 서블릿 응답을 읽으 려합니다. 기본적으로 서블릿은 2 개의 클라이언트 사이의 대화를 관리합니다. 즉, client1이 서블릿에 대해 말한 다음 서블릿에서이를 client2에 전달하는 방식으로 규칙적으로 교대로 반복합니다. – Trup
HttpServlet 인터페이스가 없습니다. 그것은 추상적 인 클래스입니다. 클라이언트는 절대 확장하지 않습니다. 서블릿은 않습니다. 서블릿과 HTTP URL은 GET 및 POST 요청을 통해 통신합니다. 귀하의 질문은 완전히 명확하지 않습니다. – EJP