[英]Get content from external web page on java
I have a following EJB: 我有以下EJB:
@Stateless
public class SomeService {
public String someOperation() {
...
}
}
So, the problem is to get content of external web page (for example http://example.com/some/link/info.xml
) and return it. 因此,问题在于获取外部网页的内容(例如http://example.com/some/link/info.xml
)并返回它。 I need something like this: 我需要这样的东西:
String pageContent = SomeFancyLibrary.getPageContent(someurl);
Sorry if this question has been already asked here, but I didnt find any info. 抱歉,是否已经在这里提出了这个问题,但是我没有找到任何信息。
From: https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html 来自: 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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.