[英]Can't get content of text file from internet server using Java
The file is located at: http://japgrammartest.freevnn.com/Chuong2.txt 该文件位于: http : //japgrammartest.freevnn.com/Chuong2.txt
This is my code: 这是我的代码:
URL url = new URL("http://japgrammartest.freevnn.com/Chuong2.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
When I call the in.readLine()
, it returns: 当我调用
in.readLine()
,它返回:
This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support
本网站需要使用Javascript,请在浏览器中启用Javascript或使用支持Javascript的浏览器
But it works fine with other sites. 但这在其他站点上也可以正常工作。 How can I fix this?
我怎样才能解决这个问题?
You can use htmlunit for that 您可以使用htmlunit
String content = ((TextPage) new WebClient().
getPage("http://japgrammartest.freevnn.com/Chuong2.txt"))
.getContent();
you can get htmlunit from maven repository with 您可以从Maven存储库获取htmlunit
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.19</version>
</dependency>
When you view source code using the below link...everything would be clear. 当您使用下面的链接查看源代码时,...一切都会清楚。
view-source:http://japgrammartest.freevnn.com/Chuong2.txt 查看源代码:http://japgrammartest.freevnn.com/Chuong2.txt
They have encrypted the page and when you call using broswer they call toHex(slowAES.decrypt(c,2,a,b))+ nethod to decrypt back.But as you are running in your java code, javascript file is missing and hence the error. 他们已经对页面进行了加密,当您使用浏览器进行调用时,他们会调用toHex(slowAES.decrypt(c,2,a,b))+ nethod进行解密。但是由于您在Java代码中运行,因此缺少javascript文件,因此错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.