我有一个以下的EJB:
@Stateless
public class SomeService {
public String someOperation() {
...
}
}
因此,问题是获取外部网页的内容(例如http://example.com/some/link/info.xml
)并将其返回。我需要这样的东西:
String pageContent = SomeFancyLibrary.getPageContent(someurl);
很抱歉,如果此问题已在此处提出,但我没有找到任何信息。
答案 0 :(得分:0)
来自:https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html
import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://www.oracle.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}